dimanche 7 juillet 2019

Trying to learn pointers, why use them instead of just &?

I'm trying to wrap my head around pointers in c++, what's the point of using a pointer vs just using &variable to get the object at that location?

For example(have not actually run this code, just for an example):

int score{10};
int *score_ptr {nullptr};

score_ptr = &score;

cout << "Address of score is: " << &score << endl;  // why not just this?
cout << "Address of score is: " << score_ptr << endl; // more work for same?

Aucun commentaire:

Enregistrer un commentaire