Thread: Odd printf behavior?

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Question Odd printf behavior?

    I just compiled the program below in Cyqwin and on codepad

    int main()
    {
    int k=1;
    printf("%d, %d, %d\n", k, k++, k++);
    }

    In both cases the output was

    3, 2, 1

    Shouldn't it be the other way around?

    Any thoughts would be welcome.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Read my answer here -> Comma Operator - C And C++ | Dream.In.Code

    Then understand that the code has undefined behaviour.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuck with function
    By scmurphy64 in forum C Programming
    Replies: 9
    Last Post: 11-10-2009, 11:41 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Newb Help: Full Arrays and Functions
    By LycanGalen in forum C Programming
    Replies: 5
    Last Post: 01-31-2008, 08:35 PM
  4. Double to Int conversion warning
    By wiznant in forum C Programming
    Replies: 15
    Last Post: 09-19-2005, 09:25 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

Tags for this Thread