c++小细节/技巧
一、
printf为整型而不是void,返回值为输出的字符串长度
例如
int a;
a=printf(“123456”);
cout<<endl;
cout<<a;
输出结果为
123456
6
二、
函数中,参数传递依靠栈实现,所以从右到左依次压栈
如
int a(int b)
{
cout<<b;
return b+1;
}
int aa(int x,int y,int z)
{
cout << endl;
cout << x + y + z << endl;
return 0;
}
int main()
{
int a1=0,a2=0,a3=0;
aa(a1=a(1),a2=a(2),a3=a(3));
return 0;
}
输出结果为
321
6
三、
#define基本上只是简单的替换
所以
#define N 2
#define M N+N
c=M/M
看似c的结果为1,实际上为
c=M/M=N+N/N+N=2+2/2+2=5