Why do I always get the output as 64..??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
2nd Feb 2019, 4:59 PM
Rushi
3 Answers
+ 11
#include <stdio.h> int main() { int i=-4,j,num; printf("num = %d\n", num); j=(num<0?0:num*num); printf ("%d\n",j); return 0; } Since you have not initialized num variable it has some garbage value which is 8. As 8 is greater than 0, the conditional expression executes the false statement which is 8*8 and that is why it prints 64
2nd Feb 2019, 5:20 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
I have a hypothesis that it gives the number the value of it's required memory size as default, if no value is given... The hypothesis wasn't true, other numeric datatypes gave 0, except int and long.
2nd Feb 2019, 5:19 PM
Seb TheS
Seb TheS - avatar
+ 1
Thanks bro.. :)
2nd Feb 2019, 5:22 PM
Rushi