-1

I'm just starting to learn about c++.

And I want to know about this

int g = &h;

what does "&h" mean in there?

I know that in here

int &e = f;

means "e" is referencing to "f".

So what are the difference between "&" in something like this

int &a = b;
int c = &d;
DeEterna
  • 13
  • 4

1 Answers1

-1

& on the left-hand-side of = means reference. On the right-hand-side, it means 'the memory address of'

e.g.

int g = &h;

Is almost certainly an error. It says, "create an integer, g, and set its value equal to the memory address of variable h.

Instead, you can have:

int *g = &h;

It says, "create a pointer to an integer, g, and set its value equal to the memory address of variable h. g points to h.

And, as you said:

int &e = f;

means e is now a reference to f

benroberts999
  • 393
  • 1
  • 10