importance or use of pointer

Here you find the importance or use of the pointer with respect to the data structure, we provide here a precise article on pointer importance or use.

If you want to check out the introduction to pointer then you can click here.

Pointer is used in memory management, optimization, function parameters, etc.

 1. Memory management: Allocating and deallocating memory as needed during run time allows you to create large objects, quickly and immediately free the memory when it is no longer required

2. Optimization: Pointers provide a performance advantage by allowing you to access computer memory directly. In a computer program, the fastest way to access and modify an object is to directly access the physical memory where that object is stored.

3. Function Parameters: Functions can return only one value, but they can take multiple parameters. Bypassing in pointers to variables as parameters, a function can be used to set the values of those variables, and the new values will persist after the function returns. Being able to set the value of several variables at once with a single function call is clean and efficient.

Other uses of pointers are following:

  • Pointers allow you to implement sharing without copying i.e. pass by reference v/s pass by copying. This allows a tremendous advantage when you are passing around big arrays as arguments to functions. Here you will not have to call the function again and again.
  • Pointers allow us to use dynamic memory allocation.
  • Pointers obviously gives us the ability to implement complex data structures like linked lists, trees, etc
  • Pointers allow us to resize the data structure whenever needed. For example, if you have an array of size 10, it cannot be resized. But, an array created out of malloc and assigned to a pointer can be resized easily by creating a new memory area through malloc and copying the old contents over.

Recommended Post:

If you find any mistake on importance or use of pointer article.

Thank you so much for your precious time.