---
title: "What is Garbage value in C or C++ and Why It Produces if we are not initialized any variables?"  
description: "What is Garbage value in C or C++ and Why It Produces if we are not initialized any variables?"  
author: "Arti Mishra"  
published: 2018-03-10  
updated: 2018-03-10  
canonical: https://answers.mindstick.com/qa/38323/what-is-garbage-value-in-c-or-c-plus-plus-and-why-it-produces-if-we-are-not-initialized-any-variables  
category: "programming"  
tags: ["c language", "c++"]  
reading_time: 1 minute  

---

# What is Garbage value in C or C++ and Why It Produces if we are not initialized any variables?

## Answers

### Answer by Sanat Shukla

The Garbage Value in C & [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus) :-When we make a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) declaration in [programming languages](https://www.mindstick.com/articles/12386/5-up-and-coming-programming-languages-to-know-about) 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](https://www.mindstick.com/forum/159479/what-are-the-differences-between-new-and-malloc-for-memory-allocation-in-c-plus-plus) has done at the [creation](https://yourviews.mindstick.com/view/85506/what-was-the-causes-of-creation-of-pakistan) time.Here some [condition](https://www.mindstick.com/forum/33737/between-condition-in-sqlserver) is behind the garbage value:1). When we explicitly [define](https://yourviews.mindstick.com/view/317/irony-of-india-even-constitution-can-t-define-minority) a variable in C or C ++, but no value is passed to them, then that [variables](https://www.mindstick.com/articles/715/php-variables) are becoming like a garbage.2). When we reach on extra [indexes](https://www.mindstick.com/articles/12525/indexes-in-sql-server) 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](https://www.mindstick.com/articles/23/garbage-collection) -

```
#include<stdio.h>

void main()

{

int a,b,c;

clrscr();

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

a=10;

b=20;

c=a+b;

printf(“\nValue of Variables After Initialization a=%d,b=%d,c=%d”,a,b,c);

getch();

} 
```

\


---

Original Source: https://answers.mindstick.com/qa/38323/what-is-garbage-value-in-c-or-c-plus-plus-and-why-it-produces-if-we-are-not-initialized-any-variables

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
