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 1 of 7.

Afri said:   1 decade ago
The formula used is *(*(a+i)+j).i represents the row and j the column.

N Prathyusha said:   1 decade ago
Please clear me the doubt that int is declared 4bytes.

How (*a[0]+1),*(*(a+0)+1) can be 2?

Shree said:   1 decade ago
I think 1006 is the memory location but why can't it be 520.

Gowthami said:   1 decade ago
Please clear information about problem.

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

*(a[0]+1) = 2

*(*(a+0)+1)=???

Sowmya said:   1 decade ago
The array begins at the location 1002 and each integer occupies 4bytes. a[0]+1 =(1002+1(is nothing but 4 bytes)) = 1006

*(a[0]+1): This is nothing but the value of the 1st element +1(since * operator is used we are accessing the value). So 1+1=2.

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.

Jithin mathew said:   1 decade ago
Thank you all.

Anonymous said:   1 decade ago
*(a[0]+1):

a[0]+1 = 1002+4 = 1006

The value at 1006 ie, the second position is 2.

Habib said:   1 decade ago
Why cant a[0] be 1, it represents the rvalue, not lvalue I guess !


Post your comments here:

Your comments will be displayed after verification.