Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

printf() and Increament Operator in C

$
0
0
Hello,
I have following code snippet

#include <stdio.h>
int main(int argc, char *argv[])
{
      int i=5;
        printf("%d %d %d %d %d\n",i++,i--,++i,--i,i);

      return 0;
}


When i calculated on my own i have answer as 4 5 5 4 5
and when i checked on compiler it gives different answer as 4 5 5 5 5

I know that in printf,its upto compiler that whether it evaluates using left to right or right to left,
but still it shows different behavior.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>