0

Please clear my silly doubt!!! 😟😓

Do integer datatypes end wid 0 nd don't go negative?

6th May 2021, 6:01 AM
Damayanti sarkar
Damayanti sarkar - avatar
7 ответов
+ 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
6th May 2021, 9:25 AM
A͢J
A͢J - avatar
+ 2
Damayanti sarkar integer is a datatype which holds default value as 0 but you can assign negative values also.
6th May 2021, 6:13 AM
A͢J
A͢J - avatar
+ 1
Thank you 🅰🅹 🅐🅝🅐🅝🅣 so much for clearing my doubt 😊
6th May 2021, 6:52 AM
Damayanti sarkar
Damayanti sarkar - avatar
+ 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
6th May 2021, 7:38 AM
Michal Doruch
+ 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.
6th May 2021, 12:32 PM
A͢J
A͢J - avatar
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
6th May 2021, 10:09 AM
Michal Doruch
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
6th May 2021, 3:55 PM
Michal Doruch