# a doubt , pl.. clear it....

Discussion in 'C' started by vignesh1988i, Jan 2, 2010.

1. ### vignesh1988iBanned

Joined:
Sep 19, 2009
Messages:
72
0
Trophy Points:
0
Location:
Chennai
void main()
{
int a,*b,**c;
a=90;
b=&a;
c=&b;
printf("%u",*(c++));
}

can u pl. say the o/p with reasons !!!!!!!!!

thank u:undecided

2. ### techgeek.inNew Member

Joined:
Dec 20, 2009
Messages:
572
17
Trophy Points:
0
Occupation:
EOC (exploitation of computers)..i m a Terminator.
Location:
Not an alien!! for sure
let me explain the whole thing with output..
for that i have changed the code little bit for ur understanding keeping the logic same...
Code:
```
# include<stdio.h>
# include<conio.h>
void main()
{
int a,*b,**c;
a=90;
b=&a;
printf("%u\n",b); //first printf
c=&b;
printf("%u\n",c);  //second printf
printf("%u\n",*(c++)); //third printf
printf("%u\n",c); //fourth printf
getch();
}
```
explaination:- the value of a is 90 and let itz address is "12345"
b is a pointer and expression b=&a assigns the address of a to b...i.e b=12345
let the address of b is "54321"
after the expression c=&b, c contains 54321
Now, the first printf gives the output:- 12345
second printf gives the output:- 54321
now let me explain the third printf:-
*c++ means first apply * over c then increase the value of c by 1. When printf is used the "*c" value is printed in the console and next time the value of c is changed +1.
so the output wud be:- *c i.e value of b i.e 12345
now finally in the fourth printf the output wud be either 54323 or 54325 depending upon whether the size of "int" is 2 or 4 bytes.In turbo C itz 2 and in visual or borland c itz 4.By pointer operation u know that if the pointer c is increased by 1 then c will acquire the new value i.e b's addr increased by int size.

Joined:
Sep 19, 2009
Messages:
72