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

#define Unexpected Output

Discussion in 'C' started by shyam_oec, Feb 1, 2008.

  1. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    #define pro(X) (X*X)
    main()
    {

    int i=3,j,k;
    j=pro(i++);
    k=pro(++i);
    printf("\n%d %d",j,k);
    getch();
    }

    output is 9 49
    can any one explain why we get second output as 49. i guessed second output to be 25 before running the above code.
     
  2. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    This is a combination of what is generally considered to be a bad macro (argument referenced twice) and the undefined behavior discussed here starting at post number 5.
     
    Last edited: Feb 1, 2008

Share This Page