----------------解决方案--------------------------------------------------------
1.下述程序的输出结果是
#include<stdio.h>
void main()
{ char a=3,b=6;
char c=a^b<<2;
printf("\n%d",c);
}
2. 设x和y都是int类型,且x=100,y=200,则 printf(“%d%d\n”,(x,y));的输出结果是
[此贴子已经被作者于2006-7-15 14:08:29编辑过]
----------------解决方案--------------------------------------------------------
2
y是负数
----------------解决方案--------------------------------------------------------
first:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char a = 3, b = 6, c;
c = a ^ b << 2;
printf("%d\n", c);
}
/**************************************************************************
*
* comment: a = 3, => binary is: 011
*
* b = 6, => binary is: 110
*
* (b << 2) => (b = 24) => binary is: 11000
*
* (a ^ b) => 011 ^ 11000 => result: 11011, so => (c = 27)
*
* so result: c = 27
*
***************************************************************************/
----------------解决方案--------------------------------------------------------
第一题是27
因为<<的优先级要高于^
所以b先左移两位为 00011000 在与a(00000011)做异或 得00011011 为27
----------------解决方案--------------------------------------------------------
second:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
int x = 100, y = 200;
printf("%d %d\n", (x, y));
exit(0);
}
/***********************************
*
* comment: 200, 0
*
* because: ',' symbol return right value
************************************/
----------------解决方案--------------------------------------------------------