References

1 – a Reference does not have memory of its own, it is another alias for pre-existing object.
It is not possible to create a reference without specifying in memory where it refers to. However, it is possible to create a free standing reference eas follows:

int & temp = 9;

in this case, we allocating memory that stores 9 and temp is a reference to it.

2 – References Cannot be neither null, nor reassigned to refer to another memory.

Pointer Arithmatics

int* a = new int[2]{1,2};
a++; // the pointer is increased by sizeof(int)

Student * s = new Student[2]{new Student(“Hesham”),new Student(“exhesham”)};
s++;
s->sayMyName(); // will print exhesham

Virtual Functions

How does Virtual function works? In C++, When declaring a virtual functions, the compiler creates a virtual table (called vtable) which stores the addresses of the virtual methods. The compiler also adds a hidden pointer in the class named vptr which points to the vtable.

Thus, when assigning a derived class to its base class, the vptr of the base class points to the vtable of the derived class. Such assignment ensures that the most derived class virtual method get called.