Вы находитесь на странице: 1из 5

# Pointers

Pointers :-Pointer is one variable which can store the address of another variable . Therefore pointer is nothing but an address. Normal variables are declared like int a; float b; .etc, but pointer variables are declared ass int *a ; float *b ; char *c ; etc. Thus * in the declareation indicates that the variable is a pointer variable . Syntax :name ; Ex: data type * variable int a=5;

a is a variable which contains 5 as its content . Address of a is denoted by &a. This address can be stored in another variable. i.e. int *p = &a ;

## thus address of a is stored in p. Hence p is a pointer.

Hence it is preceded by * . Variable p also contains address, since p is also a variable. Contents of variable a can be accesed by a or *p . *p means contents of the memory of a. Note :- * means contents of & means address of Address of operator :- & is called address of operator. Any variable preceded lby & indicates the address of memory location. Ex:int b ;

&b gives some address in which compiler allocates for a variable b 1010. Ex :int a=5 ; Int *p=&a ; Printf(%d,a); Printf(%d,*p); gives output 5 gives output 5

## Printf(%d,&a); gives output -42 Printf(%d,p); (address of a) gives output -42

Printf(%d,&p); gives output -40 (address of p) Note :- address always takes unsigned integer, thus pointer variable always tekes 2 bytes of memory inrrespective of its data type. Declaration of a double pointer :- double pointer is same as similar to the pointer, but it sotres address of another pointer variable. Ex:int a = 5 ; int *p = &a ; int **p = &p ; where a is a variable whose content is 5 and contains some address as -42 , p is a pointer variable which stores the address of a also p contains some address as -40. q is a double pointer variable which stores the address of pointer variable also q contains some address as -38. Ex :/* Example Program */

/* To print the value and address of pointer variables and normal variables */ #include<stdio.h> #include<conio.h> main() { int a=5,*p=&a,**q=&p; clrscr(); printf("a=%d\n",a); 5 */ /* gives output

## printf("*p=%d\n",*p);/* gives output 5 */ printf("&a=%d\n",&a); -42 */ /* gives output

printf("p=%d\n",p);/*gives output -42 (address of a) */ printf("&p=%d\n",&p);/*gives output -40(address of p*/ printf("q=%d\n",q);/* gives output -40 (address of a) */