2,424 views
0 votes
0 votes
Main ()

{

Int x,y , z;

X=y=z=1;

Z=++x||++y&&++z;

Printf ("x=%d y=%d z=%d",x,y,z);

}

1 Answer

Best answer
4 votes
4 votes
Whenever you have multiple precedence in equation,put parenthesis and then solve:-

1. $a+b*x$ => $( (a) + (b*c) )$ , so here firstly first parentheses (a) is evaluated and then next parenthesis.(b*c).If we dont put parenthesis then we can say a+b*c,multiply has higher precedence and it will be done first.Although it will be right but we can get some situation as you mentioned in question where without parenthesis we may get wrong answer.

Coming to question:-

$ (  (++x) | | (++y&&++z) ) $

 //because && and has high precedence so y is bounded to &&

++x will be done and ig gives 2,which means true and if LHS of or is true we dont evaluate RHS(shortcircuiting).

Soa answer =$2,1,1$
selected by

Related questions

2 votes
2 votes
2 answers
2
atulcse asked Jan 15, 2022
685 views
Consider the following programint find (int n) { int a = 1; for (i = 1; i < = n; i ++) for (j = 1; j < = i; j++) for (k = 1; k <= j, k++) a = a + 1; ...
0 votes
0 votes
0 answers
3
1 votes
1 votes
2 answers
4
sushmita asked Sep 28, 2018
441 views
void main() { char*s[]={"iceland","Greenland","Ireland","Switzerland"}; char ptr[]={s+3,s+2,s+1,s}; char *p=ptr; printf(\%s ", ++p); printf(\%s ",*(*++p+3); printf(\%s ...