when I declare a pointer, and refer to it without the *, I think I am using it as a normal variable (since I know pointers hold addresses in memory, and the * operator will retrieve the value at the address stored in the pointer). is this correct? for example:
what is "p" at the point of the commented line (without the *)? is it simply a variable at this point?Code:int i, *p; i = 1; p = &i; /* this line, I am assigning the address of i to the variable p, correct? */
forget about strings being used without their index for a second, I DO understand that this will generate the address of the first element of the string. but just that fact is probably what is leading me to this uncertainty. but also the fact that this code is legal, makes me think my answer to my above question is correct:
p would be a variable declared as a pointer to char in the above, and str would be a constant address of the first element in the string.Code:char str[80] = "somestr", *p; p = str; /* the equivalent of using &, the "address of" operator, which is unnecessary since the compiler will automatically substitute str with the address of its first element */
would anyone please just let me know if I have this all correct here?
thank you in advance!