ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int arr[2 * 3 + 1];
printf("%zu", sizeof arr / sizeof arr[0]);
}- A. 28
- B. 8
- C. 0
- D. 7
Correct answer: D. 7
2 * 3 + 1 = 7 is an integer constant expression, and sizeof arr / sizeof arr[0] counts elements, not bytes. 28 is sizeof arr alone with a 4-byte int, 8 reads the size as 2 * (3 + 1), and 0 divides the other way round.
More C Programming questions
- How many paths go from the top-left to the bottom-right of a 3 by 3 grid of points, moving right or down, without passing through the…
- What is printed? c #include <stdio.h> int main(void) { int a = 2147483647; printf("%u", (unsigned)a + 1u); }
- How many integers from 1 to 64 have their low three bits all clear? Compute with this program. c #include <stdio.h> int main(void) { int c…
- How many times does the letter g occur in "programming"? The program counts it with a pointer walk. c #include <stdio.h> int main(void) {…
- What is printed? c #include <stdio.h> int main(void) { int x = 10; printf("%d %d", x & -x, x & (x - 1)); }
- What is printed? c #include <stdio.h> int main(void) { int v[] = {3, 9, 4}; int p = v; int s = 0; while (p < v + 3) s += p++ 2…