Actually, it is the concept of run-time polymorphism. As it is very nicely described by the Salil Agrawal sir in his answer that if we call a derived class function, which is overridden in the derived class using the base class pointer it does not call the derived class function. It simply call the base class function.
In order to resolve this problem we use the virtual keyword before the function in base class. It is optional to prefix virtual keyword in derived class. when we make any function virtual in a class a virtual table get created corresponding to each which is derived from the base class. this table is known as vtable, which contains the function pointer. which is pointed by a pointer known as vptr, which is stored in the few bytes of the object. Therefore when we assign the address of derived class object to base class pointer, it calls the derived class function.
plz comment and correct me if i understand wrongly.