Like Tree1Likes
  • 1 Post By novacain

Postr and Pre increment

This is a discussion on Postr and Pre increment within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int main() { int i = 5 ; printf("\n%d %d %d %d %d",i++,i--,--i,--i,--i) ; return 0 ; ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    Unhappy Postr and Pre increment

    Code:
    #include <stdio.h>
    
    int main()
    {
    int i = 5 ;
    printf("\n%d %d %d %d %d",i++,i--,--i,--i,--i) ;
    return 0 ;
    }
    Output :
    Normally the output of the above code should be 1 2 2 3 4, but the output i'm getting is 1 2 2 2 2.
    When i provide static int or char i am getting the exact expected output.
    I am very confused with this concept.
    Can anyone tell me why?

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    The result of that line is undefined behaviour.

    Question 3.2
    Salem likes this.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post Increment an Pre Increment operators in c++
    By anil_ in forum C++ Programming
    Replies: 4
    Last Post: 11-12-2011, 08:27 PM
  2. Increment a date by 1 day?
    By fekkesh in forum C Programming
    Replies: 4
    Last Post: 03-08-2009, 04:46 AM
  3. Help with increment operator
    By capvirgo in forum C Programming
    Replies: 2
    Last Post: 02-18-2008, 11:06 PM
  4. Help with increment operator, please
    By capvirgo in forum C Programming
    Replies: 4
    Last Post: 02-18-2008, 07:06 PM
  5. Post increment and pre increment help
    By noob2c in forum C++ Programming
    Replies: 5
    Last Post: 08-05-2003, 04:03 AM

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