ProgrammingHardProduct-company MCQ pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
int a[3][2] = {{1,2},{3,4},{5,6}};
int (*p)[2] = a + 1;
int *q = (int*)p;
q++;
printf("%d %d", (*p)[0], *q);- A. 3 3
- B. 3 4
- C. 4 4
- D. 3 5
Correct answer: B. 3 4
p points at row 1 ({3,4}), so (*p)[0]=3. q starts as that row's first element address reinterpreted as int*; q++ moves one int forward to the second element of that row, value 4.
More C Programming questions
- What is printed? c int a[3] = {5,10,15}; int p = a; int q = &a[2]; while (p != q) { printf("%d ", p); p++; } printf("%d", p);
- What is printed? c int a[3] = {1,2,3}; int p = a; int arrp[1] = {p}; int pp = arrp; (pp)[1] = 99; printf("%d %d %d", a[0], a[1], a[2]);
- What is printed? c int a[3] = {1,2,3}; int p = &a[1]; int x = p[1] - p[-1]; int y = (p+1) - (p-1); printf("%d %d", x, y);
- What is printed? c int add(int a,int b){ return a+b; } int sub(int a,int b){ return a-b; } int mul(int a,int b){ return ab; } int…
- What is printed? Assume a 64-bit LP64 ABI (4-byte int) and that the matrix is stored contiguously. c int a[2][3] = {{1,2,3},{4,5,6}}; int…
- What is printed? c int p = malloc(3 sizeof(int)); for (int i = 0; i < 3; i++) p[i] = malloc(3 sizeof(int)); for (int i = 0; i < 3; i++)…