Pointer and their uses in C 1.0 :Introduction

This article is on the use of pointers in c 

So why do we use pointers in c programming ?

Ans. [Long answer]

Definition: A pointer is a variable containing the address of another variable.

A variable is just a labelled place to store some data. For example one can make variable,
with the unimaginative name of ‘Variable1’, to store an integer in C with the command

>>int Variable1;
#, store the number ‘96’ in it with

>>Variable1=96;
#and print it out with

>>printf("%d",Variable1);

Instead of referring to this data store by name, one can refer to it by its address in the computer memory.
This address can itself be put in another variable in C,such a variable being called a ‘pointer’ because its
value points to where the value of the original variable is rather than being such a value itself.

To do this one puts a ‘&’ infront of a variable to mean “give me the address of ” and a ‘*’ infront of a
pointer to mean “give me whatever is that the address ”. So one could make point a pointer,
unimaginatively called ‘Pointer1’, to the above ‘Variable1’ by the command .
Pointer = &variable;
printf("%d",*pointer) to access the value in the address .


so poin = address and *poin is the value at the address poin.

Similarly passing address to a function that stores the addresses in pointers. (Basically pointers stores addresses of the values)


Now, i will show you to access elements of a array using pointer in the below example :
 


So the name of the array is itself a pointer pointing to the 0th element of the array, and as we keep adding 1 to the address of the zeroth location we are able to access different elements of the arrray.

Comments

Popular Posts