Sunday 20 March, 2011

Pointer Operations in C


Creation
& variable  Returns variable’s memory address
Dereference
* pointer  Returns contents stored at address
Indirect assignment
* pointer = val  Stores value at address
Assignment
pointer = ptr  Stores pointer in another variable

eg. 
      if a variable  is a=24 and it is stored at memory address 2000.Consider we want to point a pointer named p at that variable,do following things.
int *p,a=24,b,c;//initializing the pointers
*p=&a;//stores 2000 address to the pointer's address
b=*p;//outputs as '24' as it returns content of pointer
*p=55;//directly stores the value at address 2000
c=p;//stores the pointer
  

No comments:

Post a Comment