int main() { int i=3,j=4; i?i++:++j; printf("first:i= %d,j= %d\r\n",i++,j); printf("second: i= %d,j= %d\r\n",i++,++j); printf("third:i= %d, j= %d\r\n", i,j++); return 0; }
The output of this program will be:
first: i= 4, j= 4 second: i= 6, j= 6 third: i= 6, j= 5
Explanation:
- In the first line, the ternary operator is used to determine whether to increment i or j. Since i is not equal to 0, i++ is executed, and i becomes 4 while j remains at 4.
- In the second line, both i and j are incremented twice, since the post-increment operator is used twice. Therefore, i becomes 6 and j becomes 6.
- In the third line, i remains at 6 while j is incremented by 1, becoming 5. This is because the post-increment operator is used with j.
原文地址: https://www.cveoy.top/t/topic/xud 著作权归作者所有。请勿转载和采集!