Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
Hello , Ritik Tanwar ..
The question is a huge concept to answer everything .. no worries I will try to give you a over view about pointers .
A pointer is a derived data type that means pointers contain memory address as their value. since these memory address are the locations in the computer memory such as RAM.
pointers can manipulate the data stored in given address location.
Example
include <iosteam>
using namespace atd;
int main()
{
int *ptr =NULL; // pointer
int x = 10; // variable that contains 10 as data
ptr = &x; \\ assigning the address of x to ptr
cout << "ptr address is "<< ptr <<endl;
cout << "ptr data is "<< *ptr <<endl;
return 0;
}
output :
ptr address is 1001// some computer address
ptr data is 10
Hope you got clear picture about pointers , let me give more clarity, I will try to explain it
suppose
X -->| 10 | --[1001]
x is variable name stores 10 in 1001 address
when
ptr = & x ;
ptr stores x's address 1001 in it
ptr -->|1001| ---|10|--x
ptr point to 1001 address
when we deference ptr we get the data actually stored in memory
cout << *ptr ;
out put is : 10
You can use all type of
char * ptr
int *ptr
double *ptr
float *ptr
why to use pointer ??
1. pointers are more efficient in handling data
2.Pointer can be uses as a reference argument which saves the memory
3. supports dynamic allocation
4.They increases execution speed
Caution !!: WRONG USAGE OF POINTER MAY BE CATASTROPHIC AND NOT SAFE TO WORK , YOU MAY END UP WITH UNDEFINED BEHAVIOR .. USE IT WISELY .
Hope I answered your question ....
if any post your doubts ..