Examveda
Examveda

What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?
#include<stdio.h>
void main()
{
    int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
    printf("%u, %u", a+1, &a+1);
}

A. 65474, 65488

B. 65480, 65488

C. 65480, 65496

D. 65474, 65476

E. None of these

Answer: Option C

Solution(By Examveda Team)

>> int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; The array a[3][4] is declared as an integer array having the 3 rows and 4 colums dimensions.

>> printf("%u, %u\n", a+1, &a+1);
The base address(also the address of the first element) of array is 65472.
For a two-dimensional array like a reference to array has type "pointer to array of 4 ints". Therefore, a+1 is pointing to the memory location of first element of the second row in array a. Hence 65472 + (4 ints * 2 bytes) = 65480
Then, &a has type "pointer to array of 3 arrays of 4 ints", totally 12 ints. Therefore, &a+1 denotes "12 ints * 2 bytes * 1 = 24 bytes".
Hence, begining address 65472 + 24 = 65496. So, &a+1 = 65496
Hence the output of


This Question Belongs to C Program >> Arrays And Strings

Join The Discussion

Related Questions on Arrays and Strings