嫡女锋芒之医品毒女:c语言试题 执行语句printf("2:%d,",printf("1:%d,",scanf("%d",&x)));以后的输出结果是____。

来源:百度文库 编辑:高考问答 时间:2024/04/29 10:06:22
A) 2:1,1:1, B) 1:1,2:1, C) 2:4,1:1 D) 1:1,2:4,
请写出详细过程4,谢谢!!!

楼上的执行顺序对的,不过不是scanf占一位,
占四位,
而是相当于把两个函数的返回值作为了变量,
scanf函数:return the number of fields successfully converted and assigned;
the return value does not include fields that were read but not assigned.
A return value of 0 indicates that no fields were assigned.
The return value is EOF for an error or if the end-of-file character or
the end-of-string character is encountered in the first attempt to read a character.
返回成功赋值的变量的个数,本题中为1,只有一个x

print函数:Each of these functions returns the number of characters printed, or a negative value if an error occurs.
返回该函数输出的字符数,本题为四个是 1:1,

所以结果是D

D
先执行printf("1:%d,",…
再执行printf("2:%d,",…
scanf占一位,所以printf("1:%d,",…输出1:1
1:%d,占四位,所以printf("2:%d,",…输出2:4

晕,你上机输入一下就知道,光执行这段语句的话啥也不出。

这样的问题也问哦
不同的输入有不同的结果