What is Garbage value in C or C++ and Why It Produces if we are not initialized any variables?

0 votes
Arti Mishra asked 10-Mar-2018 in programming by Arti Mishra
edited 10-Mar-2018 by Arti-Mishra

1 Answer

0 votes
Anonymous User answered 08-Aug-2018 by Anonymous User
The Garbage Value in C & C++ :-
When we make a variable declaration in programming languages such as C and C++ but do not set any value to it. Then that variable at that time like a waste material or garbage. But memory allocation has done at the creation time.
Here some condition is behind the garbage value:
1). When we explicitly define a variable in C or C ++, but no value is passed to them, then that variables are becoming like a garbage.
2). When we reach on extra indexes of an array and that array is on the stack, C or C++ will easily allow you to do that but it could generate the garbage. etc.
An Example for Garbage Collection - 

void main()
int a,b,c;
printf(“\nValue of Variables Before Initialization a=%d,b=%d,c=%d”,a,b,c);//it printf the garbage value
printf(“\nValue of Variables After Initialization a=%d,b=%d,c=%d”,a,b,c);