Yes, you seem to understand correctly, though be careful about that asterix (*).
A variable contains a value, while a pointer contains the location of a value.
a pointer using an asterix; eg,
You also use an asterix to dereference
the value that the pointer points to; eg,
char ch = *signp; // assign the char value at signp to the variable ch
*signp = 'm'; // store 'm' to the location pointed to by signp
Every variable is stored somewhere, so it has a location. You can store the location of a variable in a pointer using the address operation, &
. That is the ampersand that you are talking about.
When you call a function, all you can pass to it are copies of the arguments, so if you want to change an argument then you have to pass its address
so that the function can dereference
that address to change those variables. For example, swapping the values in two variables:
void swap(int *a, int *b)
temp = *a;
*a = *b;
*b = temp;
You would call that with
There's nothing magic about it. Every variable has a memory location. All the pointer contains is a memory address. You just need to understand the notation that is being used.
Oh, and also! The name of an array acts the same as a pointer. So for example:
char *strcpy(char *dest, const char *src);
No need for any ampersand, since s is already a pointer.