Introduction to pointers in c
The '&' and '*' operators:
For a variable declaration
int i=100;
Then it reserve memory space for integer,i is name given to that location which store value 100.
This memory space has some address.
Reference ('&') operator:
It is also called 'address of' and is used to access memory address.
printf("%u",&i);
output may be like this: 6875643
Indirection ('*') operator:
It is used to access the value stored at that operator.
That's why this statement gives value stored at the address
printf("%d",*(&i));
output: 3
Pointers:
Defining a pointer variable of integer type:
int *p;
p=&i;
Now to access the value at the address we will use
printf("%u",p);
printf("%d",*p);
will access value stored at that address.
Question:
We know that address of variable is an integer value then
what does it mean?
char *ch;
Answer:
It means that ch is a pointer that points an address which stores an character variable.
similarly
float *f;
It means that 'f' points to the adddress which stores an a float value.
int **q;
q=&p;
Here q is pointer which points a pointer.
q stores address of p.
Reference: http://www.cs.cf.ac.uk/Dave/C/CE.html