Thursday, 28 September 2017

What is a pointer? What are the  operations that can be performed on a pointer?


Pointer is a type of variable which further used to stores the address of another variable in a program. For example a float pointer variables are used to stores the address of float variable similarly integer pointer variables are used to store address of integer variable.



Example for declaring and assigning pointer variable to a simple variable
int *m; // declaration of pointer variable of integer type
int n =100; // declaration of simple variable of integer type
m=&n; // pointer variable stored the address of simple variable

Please note that, the pointer variable should be of the same type as simple variable whose address you want to store.

Different operations are possibly performed on pointer variables are given below:

1) Addition of integer variables to a pointer variable
2) Subtraction of integer  variables from a pointer variable
3) Subtraction of two pointers variables
4) Comparison of two pointers variables

Uses of a pointer variable in programming:
1) Pointer variables are used in performing dynamic memory allocation.
2) Pointer variables are allowed to change the values of function arguments.
3) Pointer variables are allowed to passing of array into a function as argument.
4. Pointer variables are used in performing dynamic memory de-allocation
5. Pointer variables notation are also used  for access array.


Thanks

Mukesh Rajput

No comments:

Post a Comment

Thanks
Mukesh Rajput