Concept Of Pointers In C Language 0 762

Concept Of Pointers In C Language 0 763

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 :-

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

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

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 *

Example

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. 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.

 

Previous ArticleNext Article
Indian Mirchi will serve you taste in Indian news, general knowledge and information. Hope you like the story I write here and expect your points of discussion to improve them and give the best chili test out of the story. I will write tutorials also that helps students. In case you are looking for any specific information then share me in the comment.

Send this to a friend