C
C
29. What is the difference between stack and heap memory in C++?
Stack memory is automa cally managed and used for local variables,
while heap memory is manually managed and used for dynamic memory
alloca on. Stack memory is faster and has a limited size, whereas heap
memory is larger and allows for longer life mes of variables.
30. How is excep on handling implemented in C+ +?
Excep on handling in C++ is a way to manage errors during the execu on
of a program. Instead of allowing the program to crash when an error
occurs. excep on handling helps to "catch" the error and manage it, so
the program can con nue running properly.
For excep on handling try block is used.
In try block we place code that might throw an error.
The throw statement is used to indicate that an error or excep on has
happened.
In catch block we handle the excep on and define what to do if an error
happens.
31. What is the purpose of the typedef keyword in C++?
The typedef keyword in C++ is used to give a new name (or alias) to an
exis ng data type, making the code more readable or easier to maintain.
Virtual Function
Declaring a function with the keyword virtual in the base class allows the derived class to override
it.