I
Ioannis Vranos
==> C95:
I read in some text that we get undefined behaviour in expressions when
we modify a variable more than once in the expression. So I wonder if
the following codes have undefined behaviour:
1.
#include <stdio.h>
int main()
{
int x=1;
/* implementation-dependent result? */
int y= x++/x--;
printf("%d\n", y);
return 0;
}
2. I think the following is well defined, since the expression is
evaluated from left to right, and y gets assigned the value 1.
#include <stdio.h>
int main()
{
int x=1;
int y= (x++, x--);
printf("%d\n", y);
return 0;
}
I read in some text that we get undefined behaviour in expressions when
we modify a variable more than once in the expression. So I wonder if
the following codes have undefined behaviour:
1.
#include <stdio.h>
int main()
{
int x=1;
/* implementation-dependent result? */
int y= x++/x--;
printf("%d\n", y);
return 0;
}
2. I think the following is well defined, since the expression is
evaluated from left to right, and y gets assigned the value 1.
#include <stdio.h>
int main()
{
int x=1;
int y= (x++, x--);
printf("%d\n", y);
return 0;
}