Gursheesh Singh Gursheesh Singh - 8 days ago 4x
C Question

Value Stored During char assignment

Here Is The Code:

int main()
char a=a;

why does I Print 8

and If I Change %d To %c it prints nothing.

P.S #include and stdio.h was Written.


char a = a; is a self-initialization, which is basically the same as no initialization at all. Therefore, the value of a is undefined. In practice, value is determined by is whatever happened to be stored in memory at the location of the variable before.

The numerical value of the letter a in ASCII or Unicode is 97. The number 8 is just arbitrary garbage. The compiler would, if it respected itself, give you a compile time error, not just a warning.

As things are, you probably didn't even get a warning -.-