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.

Priya said:   9 years ago
We can write a[i]=i[a]
is it work for a[i][j]=?

SOUMYA said:   9 years ago
Here %u is given instead of %d, %u gives addresS, so would it not display an error?

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;

Harshal Shirude said:   8 years ago
a[0]+1= 1002+4=> 1006.
*(a[0]+1) = 2.
*(*(a+0)+1)=> *(*((1002+0)+1)) => **(1004) => 2 = a[1].

Himanshu said:   8 years ago
How can anyone know the base address?

It can be 448 or another address as well.

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.

Gowthami said:   2 decades ago
Please clear information about problem.

Anomis said:   7 years ago
Why answer is 1006, 2, 2?

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.

Sandesh H said:   7 years ago
a[0]+1 = &a[0][1] = *(a+0)+1 // all are same and returns address of a[0][1].

since starting address is 1004 i.e &a[0][0]=1002...address of a[0][1]= &a[0][0]+4= 1002+4= 1006.

*(*(a+0)+1 = *(a[0]+1) = *(&a[0][1]) // dereferencing the address(value) i.e a[0][1]=2.


Post your comments here:

Your comments will be displayed after verification.