ProgrammingModerateTCS NQT · Wipro
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int idx = -1;
int a[3] = {1, 2, 3};
unsigned u = (unsigned)idx;
printf("%d", u < 3 ? 1 : 0);
}- A. 1
- B. 3
- C. 0
- D. 2
Correct answer: C. 0
(unsigned)-1 is 4294967295, which is not less than 3, so the test is 0. The array a is never indexed here.
More C Programming questions
- What is printed? c #include <stdio.h> int f(void) { static int s = 5; return s++; } int main(void) { int a = f(), b = f(), c = f()…
- What is printed? Assume char is 1 byte, int is 4 bytes with 4-byte alignment. c #include <stdio.h> struct S { char a[5]; int b; }; int…
- What is printed? c #include <stdio.h> enum { A, B = 5, C }; int main(void) { printf("%d %d", C, A + B); }
- What is printed? c #include <stdio.h> int main(void) { int i = 0, n = 0; while (i++, i < 5) n++; printf("%d", n); }
- What is printed? c #include <stdio.h> int main(void) { int i = 0, c = 0; do { i++; if (i % 2) continue; c++; } while (i < 6); printf("%d"…
- After sorting by squared distance from the origin, with ties broken by x ascending, what is printed? c #include <stdio.h> #include…