0
Please clear my silly doubt!!! 😟😓
Do integer datatypes end wid 0 nd don't go negative?
7 Réponses
+ 1
Name
Then why I am getting 0 here without declaring static or global variable
"Ignore the warnings"
https://code.sololearn.com/coj3l7X42uaK/?ref=app
+ 2
Damayanti sarkar
integer is a datatype which holds default value as 0 but you can assign negative values also.
+ 1
Thank you 🅰🅹 🅐🅝🅐🅝🅣 so much for clearing my doubt 😊
+ 1
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
+ 1
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.
0
Idk, maybe SoloLearns code playground implementation makes int 0 by default. But it's not standardized anywhere, so don't get it for granted
0
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