[solved] Shouldn't there be a garbage value? | SoloLearn: Learn to code for FREE!


[solved] Shouldn't there be a garbage value?

As far as I know if variable is not initialised then it should carry a garbage value then why in this question it is 0? Am I lacking some knowledge or there is something wrong with the question🤔🤔 https://www.sololearn.com/post/177828/?ref=app

11/18/2019 3:39:23 PM


6 Answers

New Answer


Arsenic 0 can be a random value but to say that the answer of that question is 0 is not correct.


Taste globals, global static and local static variable are always initialized to their defaults if not initialized explicitly. Everything else must be initialized explicitly.


If at least one element was given with an initialization, all the others should be set to zero. But since there's no initialization, afaik, it should be garbage values.


Avinesh But in the question it says "int a[10];" without the initialization and in local scope ( probably ). In your case you're indeed correct, but in this case the answer is undefined, therefore 0 is incorrect.


Here is the sample code It says that there should be a garbage value https://code.sololearn.com/cSjtWezU956C/?ref=app


I suggest that you report the question.