1. Which of the following correctly declares a function in C++?
(A) int sum(int, int);
(B) int sum(a, b);
(C) sum(int, int);
(D) function sum(int, int);
2. What is the correct way to define a function named display that takes no arguments and returns nothing?
(A) void display;
(B) display void() {}
(C) function display() {}
(D) void display() {}
3. What will the following program print?
void show() { cout << "Hello"; }
int main() { show(); return 0; }
(A) Hello
(B) No output
(C) Error
(D) show
4. Identify the function declaration among the following:
(A) int add(int a, int b) { return a + b; }
(B) int add(int a, int b);
(C) add(int a, int b);
(D) int add;
5. Which of the following defines a function named square that returns an integer?
(A) int square(int n) { return n * n; }
(B) void square(int n) { return n * n; }
(C) square(int n) { return n * n; }
(D) int square() { n * n; }
6. What is the return type of the following function?
float average(int a, int b) { return (a + b) / 2; }
(A) int
(B) float
(C) double
(D) void
7. What is the error in this code?
int add(int a, int b) { return a + b }
(A) Missing semicolon
(B) Missing parentheses
(C) Missing semicolon after return
(D) Missing semicolon after function body
8. What will the following code display?
int add(int a, int b) { return a + b; }
int main() { cout << add(2, 3); return 0; }
(A) 5
(B) 23
(C) Error
(D) Nothing
9. Which of the following is a valid function declaration?
(A) test();
(B) test void();
(C) void test;
(D) void test();
10. What is the correct function definition for int max(int x, int y)?
y) return x; else return y; }’)”> (A) int max(x, y) { if(x > y) return x; else return y; }
y) return x; else return y; }’)”> (B) int max(int x, int y) { if(x > y) return x; else return y; }
y) return x; else return y; }’)”> (C) max(int x, int y) { if(x > y) return x; else return y; }
y) return x; else return y; }’)”> (D) void max(int x, int y) { if(x > y) return x; else return y; }
11. In C++, function declaration is also known as:
(A) Function prototype
(B) Function body
(C) Function call
(D) Function scope
12. What will be printed?
void greet() { cout << "Hi"; }
int main() { greet(); greet(); }
(A) Error
(B) Hi
(C) HiHi
(D) No output
13. What is wrong with this function definition?
void display; { cout << "Hello"; }
(A) Missing parentheses in declaration
(B) Wrong return type
(C) Missing semicolon
(D) Nothing
14. Which of the following functions returns nothing?
(A) void test() { }
(B) int test() { }
(C) float test() { }
(D) char test() { }
15. How many values can a function return in C++?
(A) One
(B) Two
(C) Any number
(D) None
16. What is the output?
int getValue() { return 10; }
int main() { cout << getValue(); return 0; }
(A) Error
(B) 0
(C) 10
(D) Garbage value
17. Which of the following is incorrect?
(A) Function can have same name but different parameters.
(B) Function can return only one value.
(C) Function must be declared before it is used.
(D) Function can be declared multiple times with same signature.
18. What will this code output?
int sum(int a, int b = 5) { return a + b; }
int main() { cout << sum(10); }
(A) 15
(B) 10
(C) Error
(D) 5
19. What happens if a function is declared but not defined?
(A) Compiler error
(B) Linker error
(C) Runtime error
(D) No error
20. What is true about the main() function in C++?
(A) It cannot return 0.
(B) It must return void.
(C) It cannot have parameters.
(D) It must return an integer.
21. Identify the correct syntax to call a function named display:
(A) display;
(B) display[];
(C) display();
(D) display{};
22. What will this code print?
int add(int a, int b) { return a + b; }
int main() { cout << add(2, add(1, 2)); }
(A) 5
(B) 6
(C) 4
(D) 3
23. Which statement about function overloading is true?
(A) Functions must have the same number of parameters.
(B) Functions must have the same name but different parameters.
(C) Functions must have different names.
(D) Overloading is not allowed.
24. What is the output of this program?
void show(int a) { cout << "Int"; }
void show(double a) { cout << "Double"; }
int main() { show(5.5); }
(A) Int
(B) Double
(C) Error
(D) 5.5
25. What will this function return?
int test() { int x = 5; return x + 2; }
(A) 5
(B) 7
(C) 2
(D) Error
26. Which of the following is NOT allowed in C++ functions?
(A) Returning a value
(B) Using recursion
(C) Defining a function inside another function
(D) Function overloading
27. What happens if a function does not have a return statement but its return type is int?
(A) Error during runtime
(B) Compiler automatically returns 0
(C) Error during linking
(D) Undefined behavior
28. What will be the output?
int test() { return 3; cout << "Hello"; }
int main() { cout << test(); }
(A) 3Hello
(B) Hello3
(C) 3
(D) Hello
29. Which of the following is true about function parameters?
(A) Values are always passed by value by default.
(B) Values are always passed by reference.
(C) Values cannot be passed by reference.
(D) Parameters are optional.
30. What is the correct order?
(A) Declare → Define → Call
(B) Define → Declare → Call
(C) Call → Declare → Define
(D) Declare → Call → Define