Why does:
const char example;
(uint64*)example have a value of 140734799798420
and
*(uint64*)example have a value of 7004431430466964258
p.s. dont worry about the type cast, I am interested why the second * increases the value.
Thanks
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.
As others have said, you’ve invoked undefined behavior. No particular behavior is guaranteed.
That said, you see different values because you are printing different locations in memory — the first prints data from the memory location where
exampleis stored, and the second prints data from the memory location stored as the value ofexample.Defines a
charvariable on the stack without initializing it, so its value will be garbage; probably whatever was last stored in the location on the stack where it was allocated.Interprets the value of
exampleas a pointer to (the address of) auint64. This prints out the value stored inexampleas if it were a pointer.Dereferences that pointer. It interprets the value of
exampleas a pointer to (the address of) a uint64, then prints what is at that address as if it were a uint64.