ProgrammingHardHCL · Tech Mahindra pattern
What is printed?
What is printed?
int arr[3] = {1, 2, 3};
int (*p)[3] = &arr;
printf("%d %d", (*p)[1], *(*p + 2));- A. 2 3
- B. Compilation error: incompatible pointer types
- C. 1 2
- D. 2 2
Correct answer: A. 2 3
&arr has type int(*)[3], a pointer to the whole array, matching p's declared type. (*p) dereferences back to the array itself, so (*p)[1] = arr[1] = 2, and *(*p+2) = arr[2] = 3.
More C Programming questions
- What is printed (64-bit LP64)? c int a = 10; void vp = &a; int ip = (int )vp; char cp = (char )&a; printf("%d %zu %zu", ip, sizeof(vp)…
- What is printed? c int a = 5; int p = &a; int q = p; p = NULL; printf("%d %d", q, p == NULL);
- What is printed? c int a[2][3] = {{1,2,3},{4,5,6}}; int p = &a[0][0]; printf("%d ", (p + 4)); int (rows)[3] = a; printf("%d", ((rows +…
- What is printed? c int global = 100; int getGlobal() { return &global; } int main() { int p = getGlobal(); p = 200; printf("%d %d"…
- What is printed? c void swap(int a, int b) { int temp = a; a = b; b = temp; } int main() { int x = 1, y = 2; int p = &x, q = &y; swap(&p…
- Assume 64-bit LP64, natural alignment. What is printed? c struct A { int i; char c; }; struct B { char c; int i; }; printf("%zu %zu"…