Why is y = 8 in the below code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is y = 8 in the below code

Int y; Int X=3 y= (X<=5)? y: X Printf("%d", y);

26th May 2019, 8:06 PM
G PURNA SAI KIRAN
G PURNA SAI KIRAN - avatar
4 Answers
+ 1
y has a random value because you haven't initialized it with one.
26th May 2019, 8:26 PM
HonFu
HonFu - avatar
+ 1
Try to change the two values and see for yourself. In the beginning, y is uninitialized, so random value in it. Then, if x<=5 (which it is) y will have the value of y, otherwise of X. So y still has what it had in the beginning.
27th May 2019, 3:21 PM
HonFu
HonFu - avatar
+ 1
Great! Thanks a ton mate. That helped
27th May 2019, 3:25 PM
G PURNA SAI KIRAN
G PURNA SAI KIRAN - avatar
0
You mean to say that 8 is a random value? Nothing related to 3+5?
27th May 2019, 3:01 PM
G PURNA SAI KIRAN
G PURNA SAI KIRAN - avatar