Features and Use of Pointers in C/C++

29 Jun, 2022
Pointers store the address of variables or a memory location. Syntax:
datatype *var_name; 
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”
int *ptr;  
 Features of Pointers:
Pointers save memory space.Execution time with pointers is faster because data are manipulated with the address, that is, direct access to memory location.Memory is accessed efficiently with the pointers. The pointer assigns and releases the memory as well. Hence it can be said the Memory of pointers is dynamically allocated.Pointers are used with data structures. They are useful for representing two-dimensional and multi-dimensional arrays.An array, of any type, can be accessed with the help of pointers, without considering its subscript range.Pointers are used for file handling.Pointers are used to allocate memory dynamically.In C++, a pointer declared to a base class could access the object of a derived class. However, a pointer to a derived class cannot access the object of a base class.
Pointers save memory space.
Execution time with pointers is faster because data are manipulated with the address, that is, direct access to memory location.
Memory is accessed efficiently with the pointers. The pointer assigns and releases the memory as well. Hence it can be said the Memory of pointers is dynamically allocated.
Pointers are used with data structures. They are useful for representing two-dimensional and multi-dimensional arrays.
An array, of any type, can be accessed with the help of pointers, without considering its subscript range.
Pointers are used for file handling.
Pointers are used to allocate memory dynamically.
In C++, a pointer declared to a base class could access the object of a derived class. However, a pointer to a derived class cannot access the object of a base class.
Uses of pointers:
To pass arguments by referenceFor accessing array elementsTo return multiple valuesDynamic memory allocationTo implement data structuresTo do system-level programming where memory addresses are useful
To pass arguments by reference
For accessing array elements
To return multiple values
Dynamic memory allocation
To implement data structures
To do system-level programming where memory addresses are useful
Drawbacks of Pointers:
If pointers are pointed to some incorrect location then it may end up reading a wrong value.
Erroneous input always leads to an erroneous output
Segmentation fault can occur due to uninitialized pointer.
Pointers are slower than normal variable
It requires one additional dereferences step 
If we forgot to deallocate a memory then it will lead to a memory leak. 
guptavivek0503
sagartomar9927
C-Pointer Basics
C-Pointers
cpp-pointer
pointer
Pointers
C Language
C++
Pointers
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Unordered Sets in C++ Standard Template Library
Operators in C / C++
Exception Handling in C++
What is the purpose of a function prototype?
Sorting Vector of Pairs in C++ | Set 1 (Sort by first and second)
Vector in C++ STL
Map in C++ Standard Template Library (STL)
Initialize a vector in C++ (7 different ways)
Set in C++ Standard Template Library (STL)
Priority Queue in C++ Standard Template Library (STL)