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

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

  1. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    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.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    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.
     
  3. vignesh1988i

    vignesh1988i Banned

    Joined:
    Sep 19, 2009
    Messages:
    72
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Chennai
    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?????
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice