Skip to main content

Thread: operator precedence related question


here 2 programs

program 1
code:
#include<stdio.h>  int main()  {  int b=5;  int c= (b++)+(++b);  printf("%d",c);  }
the output of above
code:
12.
program 2
code:
#include<stdio.h>  int main()  {  int b=5;  int c= (b++) + (++b) + (++b) + (++b);   printf("%d",c);  }
the output of program 2
code:
27.
i took program 2 here logic has been explained not give output 29 on machine output 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.

code:
warning: operation on `b` may undefined [-wsequence-point]
read sequence points figure out what's going on here.

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

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support