Odd printf behavior?

This is a discussion on Odd printf behavior? within the C Programming forums, part of the General Programming Boards category; I just compiled the program below in Cyqwin and on codepad i nt main() { int k=1; printf("%d, %d, %d\n", ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 10:41 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  3. Newb Help: Full Arrays and Functions
    By LycanGalen in forum C Programming
    Replies: 5
    Last Post: 01-31-2008, 07: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21