A pointer is different. A pointer is a variable that points to another variable. This means that a pointer holds the memory address of another variable. Put another way, the pointer does not hold a value in the traditional sense; instead, it holds the address of another variable. A pointer "points to" that other variable by holding a copy of its address.
Because a pointer holds an address rather than a value, it has two parts. The pointer itself holds the address. That address points to a value. There is the pointer and the value pointed to. This fact can be a little confusing until you get comfortable with it, but once you get comfortable it becomes extremely powerful.
The following example code shows a typical pointer:
#include <stdio.h>
int main()
{
int k,l;
int *p; /* a pointer to an integer */
p = &k;
*p=5;
l=k;
printf("%d %d %d\n", k, l, *p);
return 0;
}

No comments:
Post a Comment