HitBrother

Pointers ” The Special Variables ” In C Language

Introduction:-
A pointer is a special variable that is used to store the address of some other variable. A pointer can be used to store the address of a single variable, array variable, structure, union, or even a pointer.

The concept of pointers:-
Every variable is stored in the memory, and each memory location has a numeric address. The declaration of the variable int a = 5;

Here a is the name of the variable, the value of the variable is 5 while the address of the variable is 100 (assumed).

The declaration of the variable tells the compiler to :-

Advertisement

1. Reserve space in the memory to hold the integer value.

2. Associates the name “a” with this memory location.

'); var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://ad.admitad.com/shuffle/289c251618/'+subid_block+'?inject_to='+injectTo; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); })();

3. Stores the value 5 at this location.

Pointers and the indirection operator:-

The two fundamental operators used with the pointers are:

1. address operator &


2. indirection operator

* main( )


{ int a = 5; int *p; /*pointer declaration*/

p= &a; /*copying address of variable a to the pointer p*/

*p = 10; /*indirection or use of pointer to Change the value of variable a*/

printf(“%d”, a);

printf(“%d”,*p);

printf(“%d”,*(&a));

}

All the printf statements in the above program will give the output as 10.

'); var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://ad.admitad.com/shuffle/289c251618/'+subid_block+'?inject_to='+injectTo; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); })();

Since the variable p is not an ordinary variable like any other integer variable.

It is A variable which stores the address of some other variable (a in this case).

Since p is a variable, the compiler must provide memory to this variable also.

Any type of pointer gets two bytes in the memory.

int *p1; float *p2; char *p3; all pointers p1, p2, p3 get 2 bytes each.

Advertisement