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;
}
Discussion:
61 comments Page 4 of 7.
Prabha said:
1 decade ago
We are using format specifiers as %u but instead of address values are printed. Whether it won't return any error?
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].
*(a[0]+1) = 2.
*(*(a+0)+1)=> *(*((1002+0)+1)) => **(1004) => 2 = a[1].
Kushal said:
1 decade ago
*(a[0]+1) means it gives *(1002+4)=*(1006)-> that is 2
*(*(a+0)+1) means its equal to the *(a[0][1])
*(*(a+0)+1) means its equal to the *(a[0][1])
Pratik said:
9 years ago
How to know the address when it is not given. Here the &a[0] is 1002. How can you get that?
Rupa said:
1 decade ago
Can you people pls explain how (*(a[0]+1) and *(*(a+0)+1)gives the same result in @D array??
PUSHPARAJ said:
5 years ago
*(a[0]+1) is Nothing. Just a[0][1] value is 2.
*(*(a+0)+1)) as same as a[0][1] value is 2.
*(*(a+0)+1)) as same as a[0][1] value is 2.
(4)
N Prathyusha said:
2 decades ago
Please clear me the doubt that int is declared 4bytes.
How (*a[0]+1),*(*(a+0)+1) can be 2?
How (*a[0]+1),*(*(a+0)+1) can be 2?
Abc said:
1 decade ago
a[0] equals *(a+0).
a[0][0] equals*(*(a+0)+0).
So in general a[I][J] == *(*(a+I)+J).
a[0][0] equals*(*(a+0)+0).
So in general a[I][J] == *(*(a+I)+J).
Muzna said:
1 decade ago
*(*(a+0)+1)==*(*&a[0]+1) ,now *and & will cancel and
*(a[0]+1)==*(a[0][1])==2.
*(a[0]+1)==*(a[0][1])==2.
Anonymous said:
1 decade ago
*(a[0]+1):
a[0]+1 = 1002+4 = 1006
The value at 1006 ie, the second position is 2.
a[0]+1 = 1002+4 = 1006
The value at 1006 ie, the second position is 2.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers