0

The address of a variable can be directly accessed by Ampersand....Then why do we use pointers isn't useless....

#include <iostream> using namespace std; int main() { int score = 5; int *scorePtr; scorePtr = &score; cout << scorePtr << endl; cout << &score << endl; //0x23fe44 //0x23fe44 return 0; }

15th Dec 2018, 12:20 PM
Aamir Mehmood
1 Antwort
+ 2
Pointers become very useful, when you play with memory that doesn't get assigned a variable name. They are the only way to access it. Making things like a link list for 5 nodes of data can be done with ampersand. Making it with 100,000 would be very messy and likely impossible because you would use up all of the stack space. The moment you touch new or malloc pointers are required as they are the only method of dealing with the heap.
15th Dec 2018, 4:56 PM
John Wells
John Wells - avatar