1、 int x = 3,y=4,z=5;
printf("%d",~((x^y)&&!z));
输出结果 -1
2、char s[] = "912\0912";
printf("%d",strlen(s));
输出结果 3
3、int a[100][200];
printf("%d",&a[50][4]-&a[0][3]);
输出结果 1001
4、enum months{JAN = 1,FEB,MAR,APR,MAY=3,JUN,JUL,AUG,SEP,NOV,DEC};
printf("%d",(MAR&AUG)^!JAN);
输出结果 2
5、
union foo
{
char s[13];
int i;
};
union foo f;
printf("%d",sizeof(f));
输出结果 16
6、
int cnt=0;
for(int a=-1;a>0;a++)
{
cnt++;
}
printf("%d %d",a,cnt);
输出结果 -1 0
7、
char a;
a=255;
printf("%d\n",a++);
输出结果-1
char是一个8位的有符号类型,他的取值范围是-128 ~ 127,当超过最大值时,自动从最小值开始往上加,也就是说如果a=128,那么他实际上是-128。
8、char ch='\376'; printf( "%d" ,ch);
输出结果 -2;
9、printf("12345"+3); 输出 45
10、
char * s1 = "hello";
char * s2 = "hello";
if(s1==s2)
{
cout<<"equal"<<endl;
}
else
{
cout<<"not equal"<<endl;
}
输出 “equal”
11、(来自锐捷网络)
int (*ptr)[5] = (int(*)[5])100;
printf("%d",(int)(&(*(ptr+1))[2]));
输出 128???
12、
char p;
char buf[10] = {1,2,3,4,5,6,9,8};
p = (buf+1)[5];
printf("%d",p);
输出结果为 9
13、
int a[5] = {1,2,3,4,5};
int *ptr = (int*)(&a+1);
printf("%d,%d\n",*(a+1),*(ptr-1));
输出结果为 2 5
14、
int x=1;
int y=2;
int t;
if(--x&&++y)
t=0;
else
t=1;
printf("%d",y);
输出结果 y = 2
15、
int a=2, b = 0, c;
c = a || ++b;
cout<<"a="<<a<<" b="<<b<<" c="<<c<<endl;
输出结果 a=2 b=0 c=1
16、
i+++j++;//合法
++i+++j;//不合法
17
int i=1;
int j;
j = (++i)+(++i)+(i++)+(i++)+(++i);
printf("%d,%d",i,j)
输出 6 16
18、
fun()//统计x的二进制数中1的个数
{
while(x)
{
countx++;
x = x&(x-1);
}
return countx;
}
输出为 8