Wednesday, 20 September 2017

What is a pointer? What are the operations that can be performed on a pointer? Also, point out the uses of a pointer.


What is a pointer? What are the operations that can be performed on a pointer? Also, point out the uses of a pointer.


The pointer is a variable which stores the address of another variable for eg. an integer pointer stores the address of integer variable.
                       int *x, y;
                          x=&y;
This means a gets the address of b. 
The pointer should be of the same type as the data-type of the variable whose address it is to store.

Different operations possible on pointer variables are:
  • Addition of an integer to a pointer
  • Subtraction of an integer from a pointer
  • Subtraction of two pointers
  • Comparison of two pointers

Uses of pointer variables:
  • Pointers help in performing dynamic allocation/ de-allocation of memory-blocks.
  • They allow the changed values of function arguments to be accessible in the calling function.
  • They allow the  passing of an array into a function as a function argument.
  • Pointers provide efficiency.
  • The pointer notation is also used to access array elements.


Thanks
Mukesh Rajput

No comments:

Post a Comment

Thanks
Mukesh Rajput