可能重复:
倒计时比计数更快?
哪个循环有更好的性能?我从一些地方学到了第二个更好的地方.但想知道原因.
for(int i=0;i<=10;i++)
{
/*This is better ?*/
}
for(int i=10;i>=0;i--)
{
/*This is better ?*/
}
Run Code Online (Sandbox Code Playgroud) 当我在Windows操作系统中的Code :: Blocks中运行代码时.我曾经得到一个名为对fork()的未定义引用的错误.我确实设置/选择GCC编译器作为我的默认编译器.
#include<stdio.h>
#include<unistd.h>
void main()
{
int x;
x = 0;
fork();
x = 1;
...
....
}
Run Code Online (Sandbox Code Playgroud)
请帮帮我告诉我,我可以在Windows环境下的Code :: Blocks中使用unix/linux程序吗?
我写了另一个程序,
main()
{
int x = 0;
if(x == 0)
{
printf("X = %d", x);
sleep(1000);//used delay also
x = 1;
printf("Now X = %d", x);;
}
}
Run Code Online (Sandbox Code Playgroud)
在这里它给eroor提供了对sleep()和/*延迟的未定义引用*/.
请帮我.
我是流程/任务管理的新手.我想安排两个任务.假设,
fun1()
{
printf("It will be printed in every 1 min \n");
}
fun2()
{
printf("It will be printed in every 2 min \n");
}
main()
{
fun1();
fun2();
}
Run Code Online (Sandbox Code Playgroud)
那么如何安排它们,以便我得到我想要的输出.
我希望它在Code :: Blocks(Windows)中运行.我想fun1运行1分钟,fun2运行每2分钟一次.如果我可以在两个单独的过程中完成它,那么告诉我我该怎么做.我是否需要使用信号量,互斥量和所有?
你好朋友,
我怎样才能使用函数指针数组?
如果我们将看到上面的链接,它会告诉我们函数指针是如何工作的.
现在的问题是我为什么要选择函数指针?
为什么我不能直接使用函数调用?
我会用函数指针获得什么好处?
例如
enum{a, b, c};
void A();
void B();
void C();
void (*fun[3])() = {A, B, C};
Now when I need to call a function I am doing like,
fun[a](); // This calls function A
// And so on...
Run Code Online (Sandbox Code Playgroud)
同样可以在函数调用中完成
就像我需要直接调用函数A,B或C.我可以这样
A();
B();
or
C();
Run Code Online (Sandbox Code Playgroud)
那为什么function pointer呢?
当我使用ASSERT_TRUE()提供时,Gtest我得到以下错误.
return type does not match function type带下划线VS 2010..
#include "gtest\gtest.h"
class abc {
pubilc:
bool fun();
private:
bool fun1();
};
Run Code Online (Sandbox Code Playgroud)
bool abc::fun()
{
ASSERT_TRUE(fun1()); // Getting error: return type does not match function type
}
bool abc::fun1()
{
return true; // True or false depanding on operation
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
最终C++书籍指南和列表
基本上我来自C,Embedded C领域.在这个领域工作了5年之后,我想开始使用C++.现在,我已经开始学习C++了.但是Class概念并没有点击我的脑袋.请建议我如何启动Class概念或一些简单的网站,我可以轻松地启动C++.请告诉我一些很好的C++问题(网站,我可以找到一些C++练习).
几天前,在一次采访中,一个问题被问到我,
Are function callback in C and interprocess communication are same?
Run Code Online (Sandbox Code Playgroud)
我在这个问题上有点中立.因为我处于两难境地.在IPC中,如果我们看到流程只是一个功能,我们会在流程与流程之间进行通信.这里有一个函数调用其他函数.在函数回调中我们function pointer再次使用,即一个函数调用带地址的其他函数.所以只是想知道虽然它们并不完全相同,那么有什么区别?
c operating-system function-pointers inter-process-communicat
昨天我接受采访时面试官问我存储变量的存储类.
我的回答是战争:
Local Variables are stored in Stack.
Register variables are stored in Register
Global & static variables are stored in data segment.
The memory created dynamically are stored in Heap.
Run Code Online (Sandbox Code Playgroud)
他问我的下一个问题是:他们为什么要存储在那些特定的记忆区域?为什么Local variable 没有存储register(虽然我需要auto在我的程序中经常使用变量)?或者为什么not要存储全局变量或静态变量stack?
然后我一无所知.请帮我.
我在网站上看到了以下代码.我无法理解结果是如何形成的11,而不是25或13.
为什么我在想,25因为SQ(5) 5*5
或者13因为
SQ(2) = 4;
SQ(3) = 9;
可能是最终的结果将是13 (9 + 4)
惊讶地看到结果为11.结果如何11?
using namespace std;
#define SQ(a) (a*a)
int main()
{
int ans = SQ(2 + 3);
cout << ans << endl;
system("pause");
}
Run Code Online (Sandbox Code Playgroud) 我不明白怎么回事constructors work?
在这里我宣布了一个对象obj2.它调用构造函数abc(),这非常好.
但是当我分配时
obj2 = 100
Run Code Online (Sandbox Code Playgroud)
为什么编译器允许将整数初始化为类对象?如果它完全允许它如何破坏对象,然后它是如何调用另一个参数化构造函数.
现在我有另一个问题,为什么destructor只有一次因为有two对象而被调用?
还有一个疑问,我已经是,编译器是not doing anything与default constructor那为什么默认的构造函数是required?
class abc{
public:
int a, b;
abc()
{a = 0; b = 0;}
abc(int x)
{a = x;}
~abc()
{std::cout << "Destructor Called\n";}
};
int main()
{
abc obj1;
cout << "OBJ1 " << obj1.a << "..." << obj1.b << "\n";
abc obj2;
cout << "OBJ2 " << obj2.a << "..." …Run Code Online (Sandbox Code Playgroud) c ×7
c++ ×4
windows ×2
codeblocks ×1
embedded ×1
function ×1
gcc ×1
googletest ×1
performance ×1