Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Incrementation and decrementation in C

This is a discussion on Incrementation and decrementation in C within the C and C++ forums, part of the Programming Talk category; #include<stdio.h> int main(){ int a=5; printf("%d %d %d",a++,a++,++a); return 0; } i tried this code in Visual C++ 2008 and ...

  1. #1
    pamuditha is offline Junior Member Array
    Join Date
    Apr 2011
    Answers
    1

    Question Incrementation and decrementation in C

    #include<stdio.h>
    int main(){
    int a=5;
    printf("%d %d %d",a++,a++,++a);
    return 0;
    }

    i tried this code in Visual C++ 2008 and i have get 7 6 8 as output.
    can anyone describe the fact around the output is'nt being 5,6,8.


  2. #2
    lokeshm is offline Member Array
    Join Date
    Apr 2005
    Answers
    83
    Please do not try to modify the values of your variables more than once in a single function call argument-list because the order of evaluation of operands of individual operators and sub-expressions of individual expressions, and the order in which side effects take place, is unspecified.

    Please try to read more on these topics "Sequence Points" and "Undefined Behavior"


Latest Article

Network Security Risk Assessment and Measurement

Read More...