
Strcpy(dst, src) The function call operator in action (notice the function pointer on the left side). int *array would be illegal here the compiler would not accept us assigning the Remember the NUL terminator!Ĭhar src = "This is a string.", dst Note that we use the notation because we are declaring an array. Here’s a declaration of a three- int array:

This is not useful for anything, except to declare function pointers (described later). Incidentally, C allows zero or more levels of parentheses around the variable name and asterisk: Just use your own judgment.įinally, I should point out that you can do this just fine: The absolute clearest is to keep every declaration on its own line, but that can take up a lot of vertical space. It’s even clearer to put the non-pointer variables first:

It’s possible to do the single-line declaration in a clear way.
#POINTER INDIRECTION PLUS#
Think of it as assigning each variable a base type ( int), plus a level of indirection, indicated by the number of asterisks ( ptr_b’s is zero ptr_a’s is one). If you split the declaration of ptr_a and ptr_b into multiple statements, you get this: It is not a pointer.Ĭ’s declaration syntax ignores the pointer asterisks when carrying a type over to multiple declarations. Given this, what is the type of ptr_b? int *, right?

The point of that is that the pointer is not the variable! The pointer to foo is the contents of foo_ptr. (Thus, ‘pointer variable’ really means ‘variable of a pointer type’.) There are, however, variables with different types. In fact, grammatically speaking, there is no such thing as a ‘pointer variable’: all variables are the same. This is true of all variables, regardless of type. When you access the address, you actually access the contents of the box it points to. foo is a box that is sizeof(int) bytes in size. &foo is the address of foo (which is why & is called the ‘address-of operator’). Its location in memory is called its address. We have initialised it to point to foo.Īs I said, foo occupies some memory. On a PowerPC, it occupies four bytes of memory (because an int is four bytes wide).įoo_ptr is declared as a pointer to int.
