the default value of char in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

the default value of char in c

#include <stdio.h> int main() { int a= 13; unsigned int b =37; char c ; printf("%d%d%d", a, b, c); getch(); } the output is 13 37 0 (i)why the char value is 0? (ii)when there is no initialization of 'a' and 'b' why the output of 'c' is random values?

14th Jul 2020, 3:06 PM
Nunwa_Tezpur
Nunwa_Tezpur - avatar
7 Answers
+ 9
Whenever you declare a variable, system allocates some writable memory for it. If you don't initialise it then it will contain any *garbage value* at that memory location.
14th Jul 2020, 3:11 PM
Arsenic
Arsenic - avatar
+ 1
Could be because of where the information is kept. If you used new char maybe you wouldn't have the same problem. Maybe
15th Jul 2020, 1:01 PM
Davide Floccari
Davide Floccari - avatar
+ 1
Any variable that declared hold garbage value.
16th Jul 2020, 1:45 PM
Jahanzaib Shahid
Jahanzaib Shahid - avatar
0
why 'c' has dependency on 'a' and 'b' ~ swim ~
14th Jul 2020, 3:57 PM
Nunwa_Tezpur
Nunwa_Tezpur - avatar
0
This is why you initialize variables :)
14th Jul 2020, 4:08 PM
Davide Floccari
Davide Floccari - avatar
0
so when c is not initialized and has no dependency on either 'a' or 'b' then why the 'c' value is not same in both cases ~ swim ~
15th Jul 2020, 12:58 PM
Nunwa_Tezpur
Nunwa_Tezpur - avatar
0
when used new char d and initialized 'a' and 'b'. o/p of 'c' is random but of 'd 'is 0 Davide Floccari
15th Jul 2020, 1:34 PM
Nunwa_Tezpur
Nunwa_Tezpur - avatar