int x = "H";
printf("x is %i\n", x);
I get a random 8 digit number from the console everytime I execute the above code... I have given X a definitely value, but why do I get a random value at every execution? Thank you!
int x = "H";
printf("x is %i\n", x);
I get a random 8 digit number from the console everytime I execute the above code... I have given X a definitely value, but why do I get a random value at every execution? Thank you!
That because you're assigning a "char*"
(character pointer) to your integer. Perhaps you meant this instead:
int x = 'H'; /* <-- Note single quotes, not doubles. */
printf("x is %i\n", x);
The character pointer "H"
can be put anywhere in memory the compiler/linker/loader desires (and it can change each time). You then get that memory address stored in x
(with possible loss of precision if your pointer data types have more bits than your integers).
However the character 'H'
will always be the same value (assuming you're using the same underlying character set - obviously it will be different if you compile it on an EBCDIC platform like System z USS).