1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Most confusing problem

Discussion in 'C' started by HARIT, Oct 1, 2012.

  1. HARIT

    HARIT New Member

    Joined:
    Jul 16, 2011
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    What is incremented by these oparators...address or value?? Plz come with explanation.

    ++(*y).....value/address?
    *++y.....value/address?
    ++*y.....value/address?
    *y++.....value/address?
    (*y)++.....value/address?

    Let y is a pointer.
     
  2. sumedh yadav

    sumedh yadav New Member

    Joined:
    Aug 18, 2012
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    ( )>++>* precedence and associativity left to right.
    therefore
    1)value
    2)address
    3)address
    4)address
    5)value
     
  3. HARIT

    HARIT New Member

    Joined:
    Jul 16, 2011
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include <stdio.h>
    
    int main()
    {
       int x[] = {10,20,30,40, 50}; 
       int *y;
       y= x; 
       printf("%3d%3d%3d%3d%3d",++(*y),*++y,++*y,*y++,(*y)++);
       return 0;
    }
    O/P: 31 30 21 11 10

    please explain this code to support your answer.
     

Share This Page