ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int a[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int *p = (int *)a;
printf("%d %d %d", *(p + 5), *(*(a + 1) + 2), *(a[2] + 1));- A. 6 7 11
- B. 5 7 10
- C. 6 6 10
- D. 6 7 10
Correct answer: D. 6 7 10
Treating a as flat memory, p+5 is the 6th int = 6. *(a+1) decays the row a[1] to a pointer, +2 gives a[1][2]=7. a[2]+1 points to a[2][1]=10.
More C Programming questions
- Which identifier, even though declared at file scope, never has linkage at all in C?
- What can printf legally print here? c int i = 0; printf("%d %d %d", i++, i++, i++);
- What happens when this is compiled? c int compute(int x); static int compute(int x) { return x 2; } int main(void) { printf("%d"…
- What is printed? c int a[] = {10, 20, 30, 40, 50}; printf("%d", a[1, 3]);
- What can be said about this program? c int main(void) { int arr[5]; arr[5] = 10; printf("%d", arr[5]); }
- What is the only output consistent with the C standard? c int a[3] = {10, 20, 30}; int p = a; printf("%d %d", p++, p);