Quantcast
Channel: Why are these constructs using pre and post-increment undefined behavior? - Stack Overflow
Viewing all articles
Browse latest Browse all 16

Why are these constructs using pre and post-increment undefined behavior?

$
0
0
#include <stdio.h>int main(void){   int i = 0;   i = i+++++i;   printf("%d\n", i); // 3   i = 1;   i = (i++);   printf("%d\n", i); // 2 Should be 1, no ?   volatile int u = 0;   u = u+++++u;   printf("%d\n", u); // 1   u = 1;   u = (u++);   printf("%d\n", u); // 2 Should also be one, no ?   register int v = 0;   v = v+++++v;   printf("%d\n", v); // 3 (Should be the same as u ?)   int w = 0;   printf("%d %d\n", ++w, w); // shouldn't this print 1 1   int x[2] = { 5, 8 }, y = 0;   x[y] = y ++;   printf("%d %d\n", x[0], x[1]); // shouldn't this print 0 8? or 5 0?}

Viewing all articles
Browse latest Browse all 16

Latest Images

Trending Articles



Latest Images