char* p = "hello world";
programmers usually assigns the address of an variable to a pointer. But in the above case, where is the pointer pointing to?
and what in the world is
int x =42;
int* p= &x;
int ** r = &p;
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.
It’s pointing to an area in the program’s read-only memory (usually in the program’s machine code itself) containing the ASCII sequence
hello world. Compare this to:Which creates an array of 12
chars on the stack, which is modifiable just like any other variable, and to:Which creates an array of 12
chars on the heap, and setspto be a pointer to this readable and writable space of heap memory.As for your (totally unrelated) second question:
Is simpler than it looks, though it’s also bad.
&pis the address of p. So if we did:Then the pointer
ypoints to the variablex, so assigning to*ychangesx(and vice versa). We can do this for arbitrarily complex types:Now
yis still a pointer that points tox, butxis also a pointer. So in your example,ris a pointer to a pointer to anint, and it’s value is the address ofp(a pointer to achar). However, it’s a bad idea to do this because many platforms have alignment issues with casting from achar *type to a larger pointer type.