A pointer has an address like other variables (which can't and needn't be changed) but what makes a pointer a pointer is that it's value is an address -- the address of the variable it points to (which means this address has to be a different one; *ptr=&ptr won't work).
A confusing thing about c is the difference between the syntax referencing int's and char's. Probably this is because char declarations (eg, char word[]="this") are usually arrays for strings, so you are allowed to initialize them using a "string constant" ("this") AND refer to that constant using the name of the array. With an int, the name of an array defaults to pointing to it's first element (I'll explain why at the end). Look at this:
Code:
#include <stdio.h>
int main () {
int intray[5]={'t','h','i','s','\0'};
char charray[5]={'t','h','i','s','\0'};
printf("using intray: %s\n", intray);
printf("using charray: %s\n", charray);
}
the output
using intray: t
using charray: this
So strcpy(&p, "abc"); is something you can't (and would never need to) do.
The "&" gives you the address of a variable, the same address a pointer to that variable would hold. It's usually used with single integer variables and char array names so that those variables can be passed to a function and modified without having to be returned or globalized.
Code:
#include <stdio.h>
void exampfunc (int *n) {
*n=5;
}
int main () {
int x=0;
exampfunc(&x);
printf("%d\n",x);
}
Of course the output is 5. That's because we passed the function a "pointer" (&x, the address of x). So in examplfunc, &x is *n, a pointer to some number. That means we can change the value at the address directly, rather that having to return a value for assignment. With a char array (which is more common) it looks different:
Code:
#include <stdio.h>
#include <string.h>
void exampfunc (char *n) {
strcpy(n,"that");
}
int main () {
char word[]="this";
exampfunc(word);
printf("%s\n",word);
}
No & and only one *, but the output is still that.
string t="rrrrr";
You can't work strings this way in C. You have to think of them as char arrays. When you declare a char pointer (char *word) you can use strcpy on it after you assign it some memory, since you actually need multiple memory addresses to store multiple letters -- but the pointer *word will include all the spaces assigned to it. Since you don't assign int's memory, their pointer's only cover the first value of an array.
So to conclude: strcpy(&p, "abc"); is impossible because "abc" requires an array. You can't reference anything but a character array, and for that you can't use "&".