0

In C Language , when we declare the variable as int , it will assign the space in memory and store garbage value. until, we give the input..

Similar way , what the char will store as default value ..

When I use debug feature in Code Blocks. It will assign something like 0'\000' . Is there any meaning for this representation.

Thanks in advance

hackwithharsha
  • 901
  • 1
  • 16
  • 39
  • Looks like the decimal value as well as the octal escape syntax for char (both 0). – eckes Dec 21 '14 at 21:40
  • With MSVC when compiling for debug mode certain fill values will be used for uninitialized memory depending on how the memory is allocated or freed: http://stackoverflow.com/questions/370195/when-and-why-will-an-os-initialise-memory-to-0xcd-0xdd-etc-on-malloc-free-new This can help quite a bit when debugging problems related to initialization or object lifetime. – Michael Burr Dec 21 '14 at 21:47

2 Answers2

4

The garbage value can be any combination of 8 bits, 0000 0000 to 1111 1111. There is no "standard garbage value", it's whatever was in that memory region before it was passed along to your variable.

Jite
  • 4,250
  • 1
  • 17
  • 18
  • 2
    In particular, there's no guarantee that it'll always be zero, even if it usually turns out that way when you run it in the debugger. – Wyzard Dec 21 '14 at 21:46
  • In fact I quite seldomly get zero initialized local variables. I dunno, I might be a heavy RAM user. – Jite Dec 21 '14 at 21:49
  • The OS kernel will typically zero pages of memory when they're first allocated to a process, so it can't read (possibly private) data left behind by some other process. So the *first* time your program uses a particular page of its address space, it's likely (but not guaranteed) to be zero. – Wyzard Dec 21 '14 at 21:52
1

There is no default value for garbage, it will simply have the same value that its byte of memory was last set to. However, if you allocate your variable using the calloc function, it will set the allocated portion of memory to zero.

aquilla
  • 81
  • 1
  • 3