+ 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?
9 ответов
+ 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.
+ 1
Could be because of where the information is kept. If you used new char maybe you wouldn't have the same problem. Maybe
+ 1
Any variable that declared hold garbage value.
0
why 'c' has dependency on 'a' and 'b' ~ swim ~
0
This is why you initialize variables :)
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 ~
0
when used new char d and initialized 'a' and 'b'.
o/p of 'c' is random but of 'd 'is 0
Davide Floccari