你能否告诉我下面的代码中三元(:?
)运算符应该满足哪些条件来打印****
以及+++++++
的内容?:
printf( "%s\n", count % 2 ? "****" : "++++++++" );
答案 0 :(得分:0)
%运算符是模运算符:http://en.wikipedia.org/wiki/Modulo_operation
这部分:
count % 2 ? "****" : "++++++++"
表示(伪代码)
if count is not even
return ****
else
return ++++++++
这部分
printf("%s\n", 'string')
表示(伪代码)
replace %s with string and print with a newline character
将所有内容组合在一起,如:
if count is not even
print **** with a newline character
else
print ++++++++ with a newline character