edited by
509 views
0 votes
0 votes
what is the order of evaluation (by precedence and associativity)

int x=7,y=6,z;

z=++x + y++ - ++y + x++ - --y + --x + x-- + y--;

sorry i give much lengthy expression but my intension is to clear my doubt about the fact:

pre/post which one evaluate 1st.

scan expression from right to left or left to right.

inc/dec which one evaluate first.
edited by

2 Answers

1 votes
1 votes
it will give undefined behaviour

According to ur thought I can say preincrement will increment in same line of assignment but postincrement will not increment the value in same line, it will increment the value in next line
0 votes
0 votes
You have given the lengthy expression, But it does not matter.

It will have the simplest answer : "Undefined Behaviour".

Well this also an undefined behaviour

y = (x += 5) + z;

Related questions

3 votes
3 votes
2 answers
2
admin asked Mar 31, 2020
2,515 views
Which of the following is the correct order of evaluation for the below expression? $z=x+y^*z/4\%2-1$$^*/\%+-=$$=^*/\%+-$$/^*\%-+=$$^*\% /-+=$
0 votes
0 votes
0 answers
3
Arun Rout asked May 30, 2019
284 views
output is a=34 and x=13 can anyone plzz explain#include <iostream>using namespace std;int main(){int x = 10, a;a = x++ + ++x + x++;cout << "Post Increment Operation";cout...
0 votes
0 votes
0 answers
4
erh asked Feb 9, 2017
623 views
#include <stdio.h>int main(void){int i,j,k,l;i=j=k=l=4;int a=(++i)*(++i)*(++i);int b = (j++)*(j++)*(j++);int c = (k++)*(++k)*(k++);int d = (l++)*(++l)*(++l);printf("%d\t%...