Not a typo. the & symbol in that statement returns the address of the memory at that location. &str is the address of the first byte of the character array, so &strp is the address of the third byte.
strcpy() function requires two parameters, a pointer (or the address of) to the beginning of the destination buffer and a pointer to the source buffer. In the statement I posted it is going to delete the 3d character by shifting all the remaining characters left one character.
lets assume we start with this: char str = "SACRED"; Now create two pointers (you need to know about pointers for this to make any sense to you).
// pointer to destination string
char* p1 = &str;
// pointer to source string
char *p2 = &str;
// while not end of string
while( *p2 != 0)
// copy one character from source string to destination string
*p1 = *p2;
// increment destination string
// increment source string
} // end of while statement
*p1 = 0; // null-terminate the destination string.
At the end of the first iteration of the above loop the string will be "SARRED"
second iteration: "SAREED"
last: "SARED" // only the null terminator was copied
depends on the context. *ptr refers to the byte at the address stored in the variable named ptr. When you get an error like can't covert int* to int it means that something was expecting a pointer and you passed only an integer.
You might read this tutorial. Although mostly tecnically accurate you can ignore some of the more technical comments until you understand pointers better. Concentrate on the illustrations that tutorial presents.
This has gotton off-topic so I decided to split it into its own thread.
str is a character array that is located somewhere in memory, exactly where we don't know nor do we really care. We let the compiler and the operating system figure that one out because the exact location can change from one run of the program to another.
But for the sake of arguments lets assume that the beginning of the character array named str is at address location 500. Then if you set a pointer p to point to str then the address stored in the p variable will be 500+2 or 502.
**p can be either 1) a pointer to a pointer, or 2) a two dimensional array.
I'm generally a bit leary about (2). I understand the implication that the meaning of a two dimensional array here is perhaps a simulated two dimensional array that has been dynamically allocated rather than an actual two dimensional array. Whatever I'm trying to say, it has to do with this.
>>Whats the use of a NULL pointer ?? Won't null pointer assign value 0 to the pointer
That's correct. It initializes a pointer to a known value which can not be used for anything. Its useful for testing pointers to see if they are valid. Programmers make many mistakes by attempting to use uninitialized pointers and setting them to NULL makes it easy to check that.