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!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That because you’re assigning a
"char*"(character pointer) to your integer. Perhaps you meant this instead: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 inx(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).