Lab P12 β€” Demonstrate function overloading.

NBC351 Β· Program 12⏱ 8 min read❓ 5 MCQs

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
HiThere

Explanation

  • add() overloaded by parameter type.
  • Compiler picks based on args.

Viva / Important Questions

Short Questions

  1. Difference overloading vs overriding?
  2. Can return type alone overload?

Long Questions

  1. Explain the program in detail.
  2. 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.