Thread: printf output

  1. #1
    Registered User
    Join Date
    Jan 2009

    Question printf output

    The below code gives following output:
    5 6 3
    void main()
    	int i = 3;
    	printf ("\n%d %d %d\n", i++, ++i, i++);
    	printf("%d\n", i);
    can someone explain me how?

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    That is improper use of prefix and postfix operators on the same variable in the same expression. In other words, you are getting exactly what you are asking for: undefined behavior.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    If you want to do a bit more reading on this, check these links from the comp.lang.c FAQ:

    and so on..

    Make sure you read the 'see also' references as well.

  4. #4
    Registered User
    Join Date
    Jan 2009
    Thanks guys...that was very enlightening!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. I have some questions :(
    By geekrockergal in forum C Programming
    Replies: 19
    Last Post: 02-01-2009, 09:44 AM
  3. menu problem!!! need U R G E N T help!!!
    By catcat28 in forum C Programming
    Replies: 16
    Last Post: 11-19-2007, 01:32 PM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM