I am confused with the output. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I am confused with the output.

https://code.sololearn.com/c00V5gq07BSN/#c

12th Sep 2020, 3:05 PM
tesla
tesla - avatar
4 Answers
+ 3
int x=3,y,z; Here you intilize x =3 after that y=x=10; Here x and y both are 10 z=x<10; Here you used conditional operator this will give bool value here z=x<10 (10<10) this condition is false so 0 will assign to z variable after that printf will print values x and y were 10 but z is 0 so final Output is 10 10 0 printf ("x=%d y=%d z=%d",x,y,z);
12th Sep 2020, 4:16 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
The variable a inside main is local variable.It is visible only inside the main function.It is firstly declared and not initialized so default value of a is 0 .Then it is assgned 20 so then the outputs 0 and 20.The a outside the main is global variable .
12th Sep 2020, 3:12 PM
HBhZ_C
HBhZ_C - avatar
+ 1
The program demonstrates the concept of scope. Line 2 declares a global variable "a" and assigns an initial value of 10. Line 4 within main() declares a local variable also named "a" and does not give it an initial value. When main() refers to variable "a" in the printf() statement, the compiler uses the local variable. The local "a" is uninitialized, so it prints an unpredictable value. When main() assigns a value and prints the new value, again it is using only the local variable. The global "a" is a different variable and never gets used in this program. EDIT: You have changed the program link, so now this answer, and those before, no longer apply.
12th Sep 2020, 3:31 PM
Brian
Brian - avatar
0
Check some Youtube videos about variable scope in C. Good luck 😃
12th Sep 2020, 3:15 PM
Arturop
Arturop - avatar