edited by
18,104 views
5 votes
5 votes
#include <stdio.h>
int main()
{
int y = 2;
int z = y +(y = 10);
printf("%d\n", z);
}
edited by

2 Answers

Best answer
7 votes
7 votes
int z = y +(y = 10);

Here, we are modifying y and again reading y without an intermediate sequence point (arithmetic operators are not sequence point in C, but logical || and && are). So, undefined behaviour.

Operator precedence does not specify execution order as this restricts instruction level parallelism.

https://gateoverflow.in/62411/undefined-behaviour-in-c

selected by
0 votes
0 votes
() having highest precedence

first evaluate (y=10), and modified the value of y =2 to y=10

hence z=y+(y=10) gives value of z as z=10+10 which is equal to 20

Related questions

1 votes
1 votes
1 answer
1
Archies09 asked Apr 23, 2017
3,179 views
What will be the output of the program?#include<stdio.h int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4...
0 votes
0 votes
1 answer
2
0 votes
0 votes
0 answers
4