7 AnswersNew Answer
Name Then why I am getting 0 here without declaring static or global variable "Ignore the warnings" https://code.sololearn.com/coj3l7X42uaK/?ref=app
Damayanti sarkar integer is a datatype which holds default value as 0 but you can assign negative values also.
Thank you 🅰🅹 🅐🅝🅐🅝🅣 so much for clearing my doubt 😊
Integer is not 0 by default. It can be 0, if you declare it as static or global, otherwise it will hold garbage value. Anyway, int can be signed or unsigned. It's signed by default which means, you can assign negative value to it. You can also declare it as unsigned, so you will not be able to assign negative values, but max limit will be 2x greater than with signed
Juan Pablo Segundo Not only on Sololearn, here also same thing is happening. Just click on Live Demo and see. https://www.tutorialspoint.com/default-values-of-static-variables-in-c#:~:text=datatype%20%E2%88%92%20The%20datatype%20of%20variable,By%20default%2C%20it%20is%20zero.
Idk, maybe SoloLearns code playground implementation makes int 0 by default. But it's not standardized anywhere, so don't get it for granted
According to the C Standard (6.7.9 Initialization) 10 If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. and (3.19.2) 1 indeterminate value either an unspecified value or a trap representation So there is no default value for objects with automatic storage duration. They have indeterminate values. So once again, INT IS NOT 0 BY DEFAULT