try this.

Discussion in 'C' started by pkbis28, May 28, 2010.

  1. pkbis28

    pkbis28 New Member

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    What will be the output if you will execute following c code?

    #include<stdio.h>
    int main(){
    int xyz=1000;
    int *ptr=&xyz;
    printf("%d %d",++xyz,(*(int *)xyz)--);
    return 0;
    }
     
  2. spoddar66

    spoddar66 New Member

    Joined:
    May 25, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    most probably the answer is 1000 1000
     
  3. pkbis28

    pkbis28 New Member

    Joined:
    May 25, 2010
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    The answer is totally right but will u clarify the answer?
     
  4. spoddar66

    spoddar66 New Member

    Joined:
    May 25, 2010
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    printf function follows cedecl parameter passing convention. That is parameter will pass from right to left direction.
    (*(int *)ptr)β€”-
    = (*&val)β€”
    = valβ€”-
    Here –- post decrement operator. So first it will assign its value i.e. printf function will print 1234 and value of variable val will decrement by one. So
    val = 1233
    Now second parameter will pass:
    ++val
    So, val = 1234
     

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