Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   a doubt , pl.. clear it.... (http://www.go4expert.com/forums/doubt-pl-t20576/)

 vignesh1988i 2Jan2010 20:43

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

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

 techgeek.in 2Jan2010 21:15

Re: a doubt , pl.. clear it....

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.

 vignesh1988i 4Jan2010 09:46

Re: a doubt , pl.. clear it....

ya ya i got it :) thank u.... but i have a doubt ..... in ur third printf(); statement , *(c++) is the argument... so the first precedence will go for the brackets only na..... if it is *c++ , it's ok .. but the c++ is given inside the brackets , so how it will take *c first for evaluation?????

 All times are GMT +5.5. The time now is 14:04.