您能否告诉我下面代码中的三元(:?)运算符打印****应该满足什么条件,而+++++++则满足什么条件?

printf( "%s\n", count % 2 ? "****" : "++++++++" );

最佳答案

%运算符是模运算符: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

09-30 15:53
查看更多