0

Printing memory location / usage of pointers in C++

I'm comparing two chunks of code. If we want the output to be some hexadecimal memory location, what's the benefit of assigning this memory location to another variable? For example: int score = 9; int *scorePtr; scorePtr = &score; cout << scorePtr << endl; In the above example, what's the purpose for having int *scorePtr; scorePtr = &score;? Why can't we simply write: int score = 9; cout << &score << endl; This latter one seems simpler...

17th Jul 2020, 1:37 AM
Solus
Solus - avatar
1 Réponse
+ 3
Pointers and References become MUCH more important later in the course. One you start with methods/classes/objects, they become essential for working in any project. Can't fully explain what i mean, but i assure you that they will start to make sense one you reach methods.
17th Jul 2020, 1:42 AM
Mohamad Kamar
Mohamad Kamar - avatar