Thread: operator precedence related question
here 2 programs
program 1
the output of abovecode:#include<stdio.h> int main() { int b=5; int c= (b++)+(++b); printf("%d",c); }program 2code:12.
the output of program 2code:#include<stdio.h> int main() { int b=5; int c= (b++) + (++b) + (++b) + (++b); printf("%d",c); }i took program 2 here logic has been explained not give output 29 on machine output 27.code:27.
same logic output of program 1 12.
seems correct.
want understand why in program2 output 27 , not 29.
i suspect running 'undefined behavior' territory.
read sequence points figure out what's going on here.code:warning: operation on `b` may undefined [-wsequence-point]
specifically, plus operator not sequence point, of (b++) or (++b) in statement can evaluated in order.
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk operator precedence related question
Ubuntu
Comments
Post a Comment