565 views

3 Answers

4 votes
4 votes
this is the concept of short circuiting, statement "++x && ++y ||++z" can we written as (++x&&++y) || (++z) because logical operator has left to right associativity.

first ++x will be executed as x is -1 initially, it will be incremented  as 0 and we know anding with 0 will result in 0 that's why y will not be executed. Now because in first part(++x&&++y) we are getting whole term as 0 now ||(logical or) operator will check the second part too, ++z will increment z to 0.

Final result x=0,y=-1 and z=0.
1 votes
1 votes
x=-1 y=-1 and z=-1

Here concept of short circuiting is applied

for example a&&b if a is true means a is having any value other than 0 then we will see next part b..if b is true then whole expression will give value as 1(true) as T&&T=T.if a is false in that case whole expression will be false and return 0(false) and next part b will not be executed because we have declared the result by seeing the first part a as F&&(anything)=F

on the other hand a| |b .if a is true then whole expression is true does not care about second one,in this case b will not be executed as T | | (anything ) =T .if a is false then we will see the next part b ,if b is true then whole expression will return true otherwise false. F | | F=F ,F | | T =T

now we come to our ques,here ++x will be executed and the value of x becomes 0 (false) so ++y will not be executed because 0&&(anything) =0 .now come to the second part ++z ,z will become 0 after increment so 0 | | 0 will return value 0.

hence the final value of x=0 ,y=-1,z=0
0 votes
0 votes
Because ++ operator has higher precedence than && so after ++x nothing will be executed and && will be compared returning false as ++y||++z is false

Related questions

0 votes
0 votes
2 answers
1
Lakshman Bhaiya asked Apr 21, 2018
2,530 views
Q) What is the output of the following C Program fragment#include<stdio.h>int main(){int a = 4, b = 3;printf("%d",a+++++b);return 0;} A) 7 B) 8 C) 9 ...
0 votes
0 votes
2 answers
2
bahirNaik asked Jan 13, 2016
643 views
After executing the program, I am getting 10 as the answer.Please explain and give the postfix for the expression [ z=x++-y*b/a ].
0 votes
0 votes
0 answers
3
rahul sharma 5 asked Aug 25, 2017
379 views
What is the input and output of increment/decrement operator in the C language in terms of rvalue and lvalue?
0 votes
0 votes
0 answers
4
sadiashafaque asked Aug 6, 2018
340 views
What is the output of this code in c?int main(){static int a[] [3]={0,1,2,3,4,5,6,7,8,9,10,11,12};int i=-1;int d;d=a[i++][++i][++i]; printf("%d",d); return 0;} how did 2 ...