+ 5

What is the point of pointers?

No pun intended, but I really cannot see the use in using a pointer. Can anyone give me an example of why I would need to use a pointer ?

10th Oct 2016, 11:34 PM
Blank
2 Respostas
+ 7
The pointers are variables that can store address as its value.. it is more helpful in the case of arrays... by just incrementing the pointer we can simply point the next item.. for example: I have declared a 2 dimension array : int a[2][3]={{1,2,3},{4,5,6}}; for printing this array without pointers... we have to use 2 control variables for(int i=0;i<2;i++) for(int j=0;j<3;j++) cout<<a[i][j]; but if we use pointers it will be simple... int *p=a[0]; //a[0] is the address of first element... for(int j=0;j<6;j++) { cout<<*p; p++; } is enough and it becomes much simpler for multidimensional arrays more than two...and also helpful for char data types..
11th Oct 2016, 3:25 AM
Balaji Rs
Balaji Rs - avatar
0
It is highly used in arrays, stack, que, linked list, etc.
20th Nov 2016, 9:45 AM
Manish Khurana
Manish Khurana - avatar