C |操作员|问题27

null

#include <stdio.h>
#include <stdlib.h>
int top=0;
int fun1()
{
char a[]= { 'a' , 'b' , 'c' , '(' , 'd' };
return a[top++];
}
int main()
{
char b[10];
char ch2;
int i = 0;
while (ch2 = fun1() != '(' )
{
b[i++] = ch2;
}
printf ( "%s" ,b);
return 0;
}


(A) abc( (B) abc (C) 3个ASCII值为1的特殊字符 (D) 空字符串 答复: (C) 说明: “!=”的优先级高于“=”。所以表达式“ch2=fun1()!=”(’)被视为“ch2=(fun1()!=”(’)”。因此,“fun1()!=’(’”的结果被分配给ch2。前三个字符的结果为1。微笑字符的ASCII值为1。由于前三个字符的条件为真,因此得到三个微笑。

如果我们在while语句中加一个括号,我们会得到“abc”。

#include <stdio.h>
#include <stdlib.h>
int top=0;
int fun1()
{
char a[]= { 'a' , 'b' , 'c' , '(' , 'd' };
return a[top++];
}
int main()
{
char b[20];
char ch2;
int i=0;
while ((ch2 = fun1()) != '(' )
{
b[i++] = ch2;
}
b[i] = ' ' ;
printf ( "%s" ,b);
return 0;
}


这个修改过的程序打印“abc” 这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享