What is the correct syntax to define a function in C++?
Analysis & Theory
In C++, functions are defined with a return type, like `void myFunc() {}`.
Which keyword is used to return a value from a function?
Analysis & Theory
The `return` keyword is used to return a value from a function.
What is the return type of a function that does not return any value?
Analysis & Theory
`void` is used as the return type for functions that do not return any value.
Which of the following correctly calls a function named `add`?
Analysis & Theory
Functions in C++ are called using their name followed by parentheses: `add();`
What is a function prototype in C++?
A
A function without parameters
B
A forward declaration of a function
C
A function with a return statement
D
A function that doesn't return a value
Analysis & Theory
A function prototype declares a function's name, return type, and parameters before its actual definition.
What will happen if you call a function without declaring or defining it first?
A
Compiler will guess the function
B
Function will be ignored
Analysis & Theory
Calling an undeclared function causes a compiler error.
Which of the following is true about function overloading in C++?
A
Functions with the same name but different return types
B
Functions with the same name but different parameter lists
C
Functions with different names but same parameters
D
Functions with same name and same parameters
Analysis & Theory
Function overloading allows multiple functions with the same name but different parameter types or counts.
Which of the following is the correct way to define a function that returns an integer?
C
void function() return int;
Analysis & Theory
Functions returning integers are declared as `int functionName() {}`.
In which section of a C++ program should you place the function prototype?
A
After the `main()` function
C
Before the `main()` function
Analysis & Theory
Function prototypes are usually declared before `main()` so that the compiler knows about them.
Which of the following is used to pass a variable by reference to a function?
Analysis & Theory
The `&` symbol is used in function parameters to pass arguments by reference in C++.