ProgrammingHardTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
printf("%d", 1 ? 2 : 3 ? 4 : 5);
}- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: C. 2
The conditional operator groups to the right, but since the first test is true, the result is 2 and the rest is not evaluated.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { printf("%d", (1, 2)); }
- What is printed? c #include <stdio.h> int main(void) { char c = 'a'; printf("%d", c++ == 'a' && c == 'b'); }
- What is printed? c #include <stdio.h> int main(void) { printf("%s", "ab" "cd"); }
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { printf("%u", 1 ? -1 : 0u); }
- How many partitions of 6 into distinct parts are there? The recursion below counts them. What is printed? c #include <stdio.h> int dp(int…
- How many ways are there to tile a 1 by 4 strip with 1 by 1 and 1 by 2 tiles? The recursion computes it. What is printed? c #include…