PPL FIneL Flashcards

1
Q

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

A block of code that performs a specific task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A

Function name, return type, parameters, and body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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.

A

The function does not return a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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.

A

Only after the function is called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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.

A

An error will occur.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the term for a variable passed to a function?
A. Parameter
B. Argument
C. Constant
D. Pointer

A

Argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which keyword is used to return a value from a function?
A. return
B. void
C. break
D. exit

A

return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the correct syntax to call a function named myFunction with no parameters?
A. myFunction;
B. myFunction[];
C. myFunction();
D. call myFunction();

A

myFunction();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A

Both the number and order of parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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.

A

By assigning it to a variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A function that is already defined in the C++ library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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.

A

All of the above.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

To reduce code duplication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What keyword is used to declare a function that does not return any value?
A. null
B. void
C. empty
D. none

A

void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In the function int add(int a, int b), what are a and b?
A. Arguments
B. Parameters
C. Local variables
D. Global variables

A

Parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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.

A

Overloaded functions must have different numbers or types of parameters.

17
Q

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

A declaration specifies the return type, name, and parameters; a definition includes the body.

18
Q

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.

A

The function returns an undefined value.

19
Q

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”>;

A

printName(“Alice”);

20
Q

What will be the output of the following code?

cpp
Copy code
void greet() {
cout &laquo_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.

A

The program will print “Hello!”

21
Q

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.

A

Yes, this is called recursion.

22
Q

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.

A

To pass data into the function.

23
Q

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

A function that is optimized by the compiler to reduce function call overhead.

24
Q

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 &laquo_space;“Hello”; }
C. string greet() { cout &laquo_space;“Hi”; }
D. void main() { }

A

int sum(int x, int y) { return x + y; }

25
Q

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

A user-defined function.

26
Q

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.

A

Arguments are passed when a function is called.

27
Q

How many return statements can a function have?
A. One
B. Multiple
C. None
D. Unlimited, but only the first one is executed.

A

Multiple

28
Q

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.

A

It will be ignored by the compiler.