PPL FIneL Flashcards
What is a function in C++?
A. A block of code that performs a specific task.
B. A data type for storing values.
C. A mechanism for memory allocation.
D. A library included in the program.
A block of code that performs a specific task.
What are the main components of a C++ function definition?
A. Function name, return type, parameters, and body.
B. Function name and the main() function.
C. Header files and variable declarations.
D. Only return type and parameters.
Function name, return type, parameters, and body.
What does the void keyword indicate in a function definition?
A. The function will always return an integer.
B. The function does not return a value.
C. The function must accept no arguments.
D. The function is predefined in the C++ library.
The function does not return a value.
When is a declared function executed?
A. As soon as the program starts.
B. Only after the function is called.
C. During the program compilation.
D. After the program terminates.
Only after the function is called.
What happens if a function is declared after the main() function?
A. It will execute before main().
B. An error will occur.
C. The program will ignore it.
D. The function will work normally.
An error will occur.
What is the term for a variable passed to a function?
A. Parameter
B. Argument
C. Constant
D. Pointer
Argument
Which keyword is used to return a value from a function?
A. return
B. void
C. break
D. exit
return
What is the correct syntax to call a function named myFunction with no parameters?
A. myFunction;
B. myFunction[];
C. myFunction();
D. call myFunction();
myFunction();
What must match between the function declaration and the function call when passing multiple parameters?
A. Only the number of parameters.
B. The order of parameters.
C. Both the number and order of parameters.
D. Neither number nor order of parameters.
Both the number and order of parameters.
How can a function’s result be stored?
A. It cannot be stored.
B. By assigning it to a variable.
C. By calling it without any arguments.
D. By declaring it as void.
By assigning it to a variable.
What is a predefined function in C++?
A. A function created by the user.
B. A function that is already defined in the C++ library.
C. A function without a return value.
D. A function that only operates on arrays.
A function that is already defined in the C++ library.
Which of the following is a valid function declaration in C++?
A. int myFunction();
B. void myFunction(int x, int y);
C. double calculateArea(double radius);
D. All of the above.
All of the above.
What is the primary purpose of functions in C++?
A. To reduce code duplication.
B. To increase the complexity of code.
C. To make code run faster.
D. To manage memory allocation.
To reduce code duplication.
What keyword is used to declare a function that does not return any value?
A. null
B. void
C. empty
D. none
void
In the function int add(int a, int b), what are a and b?
A. Arguments
B. Parameters
C. Local variables
D. Global variables
Parameters
Which of these statements about function overloading is true?
A. Functions cannot have the same name.
B. Overloaded functions must have different numbers or types of parameters.
C. Overloading functions is not allowed in C++.
D. Overloaded functions must always return void.
Overloaded functions must have different numbers or types of parameters.
What is the difference between a function declaration and a function definition?
A. A declaration specifies the return type, name, and parameters; a definition includes the body.
B. A declaration only includes the return type; a definition includes the name and parameters.
C. There is no difference between them.
D. A declaration must come after the definition.
A declaration specifies the return type, name, and parameters; a definition includes the body.
What happens if a return statement is missing in a non-void function?
A. A runtime error occurs.
B. The function returns an undefined value.
C. The program crashes.
D. The function automatically returns 0.
The function returns an undefined value.
Which of the following is a valid function call for void printName(string name)?
A. printName[“Alice”];
B. printName(“Alice”);
C. printName{“Alice”};
D. printName<“Alice”>;
printName(“Alice”);
What will be the output of the following code?
cpp
Copy code
void greet() {
cout «_space;“Hello!”;
}
int main() {
greet();
return 0;
}
A. The program will print “Hello!”
B. The program will throw an error.
C. The program will do nothing.
D. The program will print nothing.
The program will print “Hello!”
Can a function be called from within another function in C++?
A. Yes, this is called recursion.
B. No, functions must be independent.
C. Only if the function is defined after main().
D. Only if the function returns void.
Yes, this is called recursion.
What is the purpose of function parameters?
A. To define the return type of a function.
B. To pass data into the function.
C. To store the function’s result.
D. To execute a function automatically.
To pass data into the function.
What is an inline function in C++?
A. A function defined inside a class.
B. A function that is optimized by the compiler to reduce function call overhead.
C. A function that can only be used once.
D. A function declared without parameters.
A function that is optimized by the compiler to reduce function call overhead.
Which of the following is an example of a function returning a value?
A. int sum(int x, int y) { return x + y; }
B. void display() { cout «_space;“Hello”; }
C. string greet() { cout «_space;“Hi”; }
D. void main() { }
int sum(int x, int y) { return x + y; }
In the following code, what is max?
cpp
Copy code
int max(int x, int y) {
return (x > y) ? x : y;
}
A. A keyword in C++.
B. A user-defined function.
C. A predefined function.
D. An inline operator.
A user-defined function.
Which of the following statements is true about arguments?
A. Arguments are passed when a function is called.
B. Arguments must always match the parameters by name.
C. Arguments and parameters are completely unrelated.
D. Arguments are only used in void functions.
Arguments are passed when a function is called.
How many return statements can a function have?
A. One
B. Multiple
C. None
D. Unlimited, but only the first one is executed.
Multiple
What happens if a function is not called in a program?
A. It will still execute.
B. It will be ignored by the compiler.
C. It will cause a runtime error.
D. It will crash the program.
It will be ignored by the compiler.