ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a[4] = {10,20,30,40};
int *arr[4];
for (int i = 0; i < 4; i++) arr[i] = &a[i];
int **pp = arr;
pp += 2;
printf("%d %d", **pp, *(*pp + 1));- A. 30 40
- B. 30 30
- C. 20 30
- D. 40 30
Correct answer: A. 30 40
pp += 2 advances by 2 elements of arr (pointers), landing on arr[2] = &a[2]. **pp dereferences to a[2]=30. *pp is &a[2], so *(*pp+1) is a[3]=40.
More C Programming questions
- Which declaration correctly declares p as an array of 10 pointers to functions taking no arguments and returning a pointer to int?
- What is printed? c char words[] = {"bat", "cat", "rat", "mat"}; char p = words + 1; char q = words + 3; printf("%ld", (long)(q - p));
- What is printed? (This program has no undefined behavior.) c char fmt(int n) { static char buf[16]; sprintf(buf, "%d", n); return buf; }…
- What is printed? Assume a 64-bit LP64 ABI (4-byte int). c int a[3][2] = {{1,2},{3,4},{5,6}}; int (p)[2] = a; p = p + 2; printf("%ld %d"…
- Which statement about this code is correct? c int add(int a, int b) { return a + b; } int main(void) { int (fp)(int) = (int ()(int))add…
- What is printed? c int a[3] = {1,2,3}; int parr[3] = {a, a+1, a+2}; int pp = parr; (pp + 1) += 10; printf("%d %d %d", a[0], a[1], a[2]);