Lab P12 β Demonstrate function overloading.
Aim
Aim: Demonstrate function overloading.
Theory
Demonstrate function overloading.
C++ Program
#include
using namespace std;
int add(int a,int b){ return a+b; }
double add(double a,double b){ return a+b; }
string add(string a,string b){ return a+b; }
int main(){ cout< Expected Output
5
6
HiThereExplanation
- add() overloaded by parameter type.
- Compiler picks based on args.
Viva / Important Questions
Short Questions
- Difference overloading vs overriding?
- Can return type alone overload?
Long Questions
- Explain the program in detail.
- Discuss key concepts demonstrated.
MCQ Practice
1. Function overloading based on:
- Param types/count
- Return type only
- Name
- Access
Answer: Param types/count.
2. Return type alone cannot:
- Overload
- Compile
- Run
- None
Answer: Overload.
3. Overloaded functions share:
- Name
- Body
- Params
- None
Answer: Name.
4. Resolved at:
- Compile time
- Run time
- Link time
- Never
Answer: Compile time.
5. Overloading is a form of:
- Polymorphism
- Inheritance
- Encapsulation
- None
Answer: Polymorphism.
Quick Revision
- Same name, different params.
- Compile-time resolution.