C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 12)
12.
What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?
#include<stdio.h>

int main()
{
    int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
    return 0;
}
448, 4, 4
520, 2, 2
1006, 2, 2
Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
61 comments Page 3 of 7.

ShahiZzZ RuLeZzZ said:   1 decade ago
We can write *(a+0)as a[0] bcoz a[i]=*(a+i).
so *(*(a+0)+1)further can be writen as *(a[0]+1).
as a[0]=1002 so *(1002+4)
now it will return the value at memory location 1006 n dat is 2.

So *(*(a+0)+1)=2.

Rookie said:   1 decade ago
In both of the cases its just printing the value at a[0][1] and that's what exactly both the expression means.

Both *(a[0]+1)=a[0][1];
And *(*(a+0)+1)=*(a[0]+1)

As a[i]=*(a+i);

Thanks.

Satishp said:   1 decade ago
*(a[0]+1)-> it is increment in the address of the arry 0 to 1.

*(*(a+0)+1)-> it is the arry is added to 0.and incemented by 1.
so the both values of these are 2 and 2.

Mayank said:   1 decade ago
In gcc compiler the code is showing following error:

Warning: format \'%u\' expects argument of type \'unsigned int\', but argument 2 has type \'unsigned int *\' [-Wformat].

Nagu said:   8 years ago
The base address is (int a=448).i using integer then i increment (a+1) the base address is 452.
integer 4 byte in linux.
integer 2 byte in Turbo c.

Sriman said:   1 decade ago
s[i]=*(s+i) and,

i[s]=*(s+i). both are same. Only the way of declaration is different.

Similarly,

a[0] can also write as *(a+0). Both are same.

Pankaj said:   1 decade ago
Here *(*(a+0)+1)
in this expiration a+0=a is the starting adders of array *a And now add the value of inter 4 so it will same expiration as second

Preethi said:   1 decade ago
a[0]+1= 1002+4=> 1006

*(a[0]+1) = 2

*(*(a+0)+1)=> I think (a+0) and a[0] is same.

So a[0]+1 the next element is being getting pointed.

Prakash said:   7 years ago
*(*(a+0)+1)=*(a[0]+1)=*(1000+1)=*(1004)=2.

Means: *(a+0)= a[0] and *(1004) bcz datatype is inetger so pointer always incremented by 4.

Vikash Mishra said:   8 years ago
According to me,

a[0]=1002;
and 1=4 bytes //because talking about address not talking about value.
so->1002+4=1006;
*(a[0]+1)=2;


Post your comments here:

Your comments will be displayed after verification.