+ 3

From where the garbage value comes in c or c++ programs ?

28th Jun 2018, 2:23 PM
Allabaksh Lukade
Allabaksh Lukade - avatar
2 Answers
+ 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.
28th Jun 2018, 3:46 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
+ 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.
28th Jun 2018, 3:39 PM
hinanawi
hinanawi - avatar