ProgrammingHardTCS NQT · Infosys · Product Company SDE
What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int main(void) { int sum = 0, i; for (i = 6; i < 24; i += 4) if (i % 2 == 1) sum += i; printf("%d %d", sum, i); return 0; }
- A. 22 26
- B. 1 26
- C. 0 26
- D. 0 24
Correct answer: C. 0 26
The loop visits 6, 10, … while i < 24; qualifying values add up to 0; after the loop i is the first value ≥ 24, i.e. 26.
More C Programming questions
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- Assume a 64-bit LP64 ABI. What is printed? c int a[4] = {1,2,3,4}; int (p)[4] = &a; printf("%d %d %zu", (p)[2], p, sizeof(p));
- What is printed? c int a[] = {1,2,3,4,5}; int p = a + 3; int q = a; printf("%d %d %d", p - q, p-- , p);