ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
printf("%d", 5 > 3 ? 2 > 1 ? 7 : 8 : 9);
}- A. 7
- B. 8
- C. 9
- D. 2
Correct answer: A. 7
The conditional operator groups to the right, so the inner test 2 > 1 chooses 7 and the outer test 5 > 3 keeps that result.
More C Programming questions
- What is printed? c #include <stdlib.h> #include <stdio.h> int cmp(const void a, const void b) { int x = (const int )a, y = (const int )b…
- What is printed? c #include <stdio.h> unsigned fib(unsigned n) { unsigned a = 0, b = 1; for (unsigned i = 0; i < n; i++) { unsigned t = a…
- What is printed? c #include <stdio.h> void rev(const char s) { if (s == '0') return; rev(s + 1); putchar(s); } int main(void) {…
- What is printed? c #include <stdio.h> int calls = 0; int A(int m, int n) { calls++; if (m == 0) return n + 1; if (n == 0) return A(m - 1…
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0x16D; printf("%u", x & 0xF); }
- What is printed? Assume unsigned int is 32 bits. c #include <stdio.h> int main(void) { unsigned x = 32, b1 = (x >> 1) & 1u, b5 = (x >> 5)…