In C, a string literal like "I can’t understand why" is stored as a char array, so that memory is available for the entire duration of the program (all addresses are pulled from the air and are not intended to represent any particular platform or architecture):
Item Address 0x00 0x01 0x02 0x03 ----- ------- ---- ---- ---- ---- "I..." 0x00080000 'I' ' ' 'c' 'a' 0x00008004 'n' ''' 't' ' ' 0x00008008 'u' 'n' 'd' 'e' 0x0000800C 'r' 's' 't' 'a' 0x00008010 'n' 'd' ' ' 'w' 0x00008014 'h' 'y' 0x00 0x??
A string literal is also an array expression, and in most contexts, an expression of the type "N-element array of T " will be converted to a type "pointer to T ", and its value will be the address from the first element of the array (exceptions are that the array expression is the operand of the sizeof or unary & or operators is the string literal used to initialize the array in the declaration).
So when you write
char* charPtr = "I can't understand why";
you copy the address of the string literal to charPtr :
Item Address 0x00 0x01 0x02 0x03 ---- ------- ---- ---- ---- ---- charPtr 0xffbe4000 0x00 0x08 0x00 0x00
Please note that if the ad was
char str[] = "I can't understand why";
str would be allocated as a char array long enough to hold the string, and the contents of the string would be copied to it:
Item Address 0x00 0x01 0x02 0x03 ----- ------- ---- ---- ---- ---- str 0xffbe4000 'I' ' ' 'c' 'a' 0xffbe4004 'n' ''' 't' ' ' 0xffbe4008 'u' 'n' 'd' 'e' 0xffbe400C 'r' 's' 't' 'a' 0xffbe4010 'n' 'd' ' ' 'w' 0xffbe4014 'h' 'y' 0x00 0x??
When you write
int* intPtr = 60;
you initialize the value of the pointer to 60 without setting it to point to an anonymous integer with a value of 60:
Item Address 0x00 0x01 0x02 0x03 ---- ------- ---- ---- ---- ---- intPtr 0xffbe4004 0x00 0x00 0x00 0x3C
Address 60 is most likely not a valid address, so trying to dereference intPtr will most likely result in undefined behavior.
If you wrote something like
int x = 60; int *intPtr = &x;
then you will have this situation:
Item Address 0x00 0x01 0x02 0x03 ---- ------- ---- ---- ---- ---- x 0xffbe4004 0x00 0x00 0x00 0x3C intPtr 0xffbe4008 0xff 0xbe 0x40 0x04
In this case, the value of intPtr is the address of x .
Finally, note that initialization and assignment are not the same thing.
T *x = value;
does not invoke x and assigns the result value ; it assigns value directly to x . The value type is treated as T * . Please note that you should receive alerts on
int *intPtr = 60;
along the lines of "creating a pointer from a whole without a cast".