Application of Pointers in C++

Following are the Applications of Pointers in C++:

  • To pass arguments by reference: Passing by reference serves two purposes
  • For accessing array elements: The Compiler internally uses pointers to access array elements.
  • To return multiple values: For example in returning square and the square root of numbers.
  • Dynamic memory allocation: We can use pointers to dynamically allocate memory. The advantage of dynamically allocated memory is, that it is not deleted until we explicitly delete it.
  • To implement data structures.
  • To do system-level programming where memory addresses are useful.

Pointers and References in C++

In C++ pointers and references both are mechanisms used to deal with memory, memory address, and data in a program. Pointers are used to store the memory address of another variable whereas references are used to create an alias for an already existing variable.

Similar Reads

Pointers in C++

Pointers in C++ are a symbolic representation of addresses. They enable programs to simulate call-by-reference and create and manipulate dynamic data structures. Pointers store the address of variables or a memory location....

Application of Pointers in C++

...

Features and Use of Pointers in C++

Following are the Applications of Pointers in C++:...

‘this’ Pointer in C++

The Pointers have a few important features and uses like it saves memory space, they are used to allocate memory dynamically, it is used for file handling, etc. Pointers store the address of variables or a memory location. Example: pointer “ptr” holds the address of an integer variable or holds the address of memory whose value(s) can be accessed as integer values through “ptr”....

References in C++

The ‘this’ pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. ‘this’ pointer is not available in static member functions as static member functions can be called without any object (with class name). Even if only one member of each function exists which is used by multiple objects, the compiler supplies an implicit pointer along with the names of the functions as ‘this’. Declaration:...

Pointers vs References

When a variable is declared as a reference, it becomes an alternative name for an existing variable. A variable can be declared as a reference by putting ‘&’ in the declaration. There are 3 ways to pass C++ arguments to a function:...