-1

To elaborate the title, what is the difference between

book& a = b;

and

book* a = &b;

After learning C, these class declaration is really confusing me. Can anyone explain how these two line of codes work individually?

slow
  • 805
  • 3
  • 13
  • 27

1 Answers1

0

first one the reference variable and second one is pointer variable.

book& a = b;

meaning of above statement is:

variable "a" referencing same memory of variable "b". so if value of "b" changes it's automatically reflect to "a" and vice versa.

book *a=&b;

means variable "a" is pointer variable it will store address of "b".

Difference for reference variable memory will be same for both variable, but in pointers memory for both variable will be different.

rishikesh tadaka
  • 483
  • 1
  • 6
  • 18