+ 3
From where the garbage value comes in c or c++ programs ?
2 Respuestas
+ 3
The operating system is responsible for managing all activities that involves the mamory access and storage allocation in the lowest level. Garbage values in particular don't be created. They exist there because no one knows which program previously stored its stuff there*. Hence, you want to make sure that each variable being initialized to a meaningful value.
_____
* For example, you would declare a simple integer value as
int a;
a's storage is reserved in stack. Then you make a query of its current value as
cout << a;
output -6394722749
The above output has no meaning except that is was being used by a program before. By which program and for what purpose is unknown.
+ 1
garbage values are just random stuff left over in computer memory that were never cleared so when you try to access them via memory addresses and such, you get seemingly random values.