Function overloading — C++ MCQs

30
Score: 0
Attempted: 0/30
1. What is function overloading in C++?



2. Which of the following is an example of function overloading?



3. What will this code output?
void test(int a) { cout << "int"; }
void test(double a) { cout << "double"; }
int main() { test(3.5); }




4. Which rule must be followed for function overloading?



5. What is the output of this code?
void show() { cout << "No arg"; }
void show(int a) { cout << "Int arg"; }
int main() { show(); }




6. What happens if two functions differ only in return type?



7. Which of the following is a valid overloaded function set?



8. What is the output of this code?
void area(int r) { cout << "Circle"; }
void area(int l, int b) { cout << "Rectangle"; }
int main() { area(4,5); }




9. What will be printed?
void print(int a) { cout << "Int"; }
void print(char c) { cout << "Char"; }
int main() { print('A'); }




10. Function overloading is resolved at:



11. What will this code output?
void calc(int a, int b) { cout << a + b; }
void calc(double a, double b) { cout << a * b; }
int main() { calc(2, 3); }




12. What will this program print?
void print(string s) { cout << "String"; }
void print(char c) { cout << "Char"; }
int main() { print("A"); }




13. Can constructors be overloaded in C++?



14. What happens when overloaded functions are ambiguous?



15. Which of the following causes a compilation error?



16. What will be printed?
void fun(int a, double b) { cout << "int double"; }
void fun(double a, int b) { cout << "double int"; }
int main() { fun(2, 3.5); }




17. What is the output of this program?
void test(int a) { cout << "Int"; }
void test(float a) { cout << "Float"; }
int main() { test(5.0); }




18. Can default arguments and overloading be used together?



19. What will the output be?
void sum(int a, int b = 2) { cout << a + b; }
void sum(int a) { cout << a; }
int main() { sum(5); }




20. Which one is NOT allowed in function overloading?



21. What will be printed?
void display(int a) { cout << "Integer"; }
void display(float a) { cout << "Float"; }
int main() { display(2.0f); }




22. What happens if a call matches two overloaded functions equally?



23. Which of the following is TRUE about overloaded functions?



24. What is the output of this code?
void show(int a, int b) { cout << "Two ints"; }
void show(int a) { cout << "One int"; }
int main() { show(10, 20); }




25. Function overloading helps to:



26. What is the output?
void calc(int a) { cout << "Int"; }
void calc(float a) { cout << "Float"; }
void calc(double a) { cout << "Double"; }
int main() { calc(5); }




27. Can operator overloading and function overloading coexist in C++?



28. Which of the following is false about function overloading?



29. What will this code print?
void calc(int a, double b) { cout << "A"; }
void calc(double a, int b) { cout << "B"; }
int main() { calc(2.0, 3); }




30. Function overloading is an example of:



Contents Copyrights Reserved By T4Tutorials