ProgrammingHardGATE CS · Product company OA
With 4-byte int, what is printed?
With 4-byte int, what is printed?
int a[3] = {7, 8, 9};
int (*p)[3] = &a;
printf("%d %d %zu", (*p)[1], **p + 1, sizeof *p);- A. 8 8 8
- B. 8 9 12
- C. 8 8 12
- D. 7 8 12
Correct answer: C. 8 8 12
*p is the whole array a, so (*p)[1] = 8 and sizeof *p = 12. **p is a[0] = 7, and + 1 applies after the dereference, giving 8, not a[1] + 1. '8 8 8' treats *p as a pointer.
More C Programming questions
- What is printed? c int c = 0, calls = 0; void comb(int start, int n, int k) { calls++; if (k == 0) { c++; return; } for (int i = start; i…
- What is printed? c int x = 3, y = 1; printf("%d %d", !x == y, !(x == y));
- For ints a and b with b != 0 and no overflow, which statement is always true in C99 and later?
- Why should a header file shared by several .c files not contain the line int counter = 0;?
- With 4-byte int, what is printed? c int n = 0; int f(void) { n++; return 1; } int main(void) { sizet s = sizeof(f()); printf("%zu %d", s…
- What is printed? c int n = 3, s = 0; while (n--) s += n; printf("%d %d", s, n);