1.
Upload your response
2.
What is the output for the segment of code shown below:
Correct Answer
A. B9
Explanation
The given segment of code is a sequence of characters. The output for this segment of code is the characters "B9" because it is the last line of the code.
3.
Which of the following is FALSE about function ?
Correct Answer
D. The function of a void function can be called in the numerical expression.
Explanation
The function of a void function cannot be called in a numerical expression because a void function does not return a value. Void functions are used for performing actions or tasks without returning any value. They are typically used for tasks such as printing output, updating variables, or performing calculations without returning a result. Therefore, they cannot be used in numerical expressions where a value is expected to be returned.
4.
Given the function prototype: void test (int, int, int&); Which of the following calling function statements is INVALID?
Correct Answer
A. Test(2, 4, 5);
Explanation
The function prototype for test() expects the third parameter to be of type int&, which means it should be a reference to an integer. In the calling function statement test(2, 4, 5), the third argument is a literal value 5, which cannot be passed as a reference. Hence, this calling function statement is invalid.
5.
What is the return type for the following function prototype ?char FindCode(int, double, float, char) ;
Correct Answer
A. Char
Explanation
The return type for the given function prototype "FindCode" is char. This is indicated by the "char" keyword before the function name. The return type specifies the type of value that the function will return when it is called. In this case, the function is expected to return a value of type char.
6.
The function prototype Example( ) is as given below:void Example (int x, int y, float z);Which of the following function call is VALID?
Correct Answer
B. Example (x, y, z);
Explanation
The function call "Example (x, y, z);" is valid because it matches the function prototype. The function prototype specifies that the function Example takes three arguments: an int, an int, and a float. In the given function call, the variables x, y, and z are being passed as arguments, which match the expected types. Therefore, this function call is valid.
7.
Which of the following function prototypes with two integer parameters can be used for a void function named CalculateBalance?
Correct Answer
C. Void CalculateBalance (int, int);
Explanation
The correct answer is "void CalculateBalance (int, int)". This function prototype takes two integer parameters, which matches the requirement of the void function named CalculateBalance. The other function prototypes either have only one integer parameter or return an integer value, which do not fulfill the requirements.
8.
What is the output for the following program?char testYou (int a, int& b, float c){ a = b * c; b = a + c; return 'K';}void main{ int x = 3; int y = 4; int z = 2; char T = testYou (x,y,z); cout<<x<<" "<<y<<" "<<z<<" "<<T;}
Correct Answer
B. 3 10 2 K
Explanation
The program defines a function called testYou that takes two integer parameters and one float parameter. Inside the function, the value of the first parameter (a) is updated by multiplying the second parameter (b) with the third parameter (c). Then, the value of the second parameter (b) is updated by adding the updated value of a and the value of c. The function returns the character 'K'.
In the main function, three integer variables x, y, and z are initialized with the values 3, 4, and 2 respectively. The function testYou is called with these variables as arguments and the returned value is stored in the variable T. Finally, the values of x, y, z, and T are printed, resulting in the output "3 10 2 K".
9.
What is the return type of the following function prototype?int function (char a, float v, double t);
Correct Answer
B. Int
Explanation
The return type of the given function prototype is int. This is indicated by the "int" keyword before the function name. It means that the function will return a value of type int after its execution is complete.
10.
Given the following prototype:float test (int, int, int);Which of the following is VALID?
Correct Answer
D. Cout
Explanation
The given prototype declares a function named "test" that takes three integer parameters and returns a float value. The "cout" statements are unrelated to the prototype and are not valid in this context. The "cout" statement is used for outputting data to the console, while the prototype is used for declaring a function signature.
11.
What is the output of the following program segment?void func (int &, int);void main( ){ int a = 10, b = 20; func (a, b); cout << a << " " <<b;}void func (int &x, int y){ x = x /3; y = x; cout << x << " " << y << endl;}
Correct Answer
A. 3 3
3 20
Explanation
The program segment defines a function called "func" that takes in two parameters, an integer reference "x" and an integer "y". In the main function, two integer variables "a" and "b" are declared and initialized with the values 10 and 20 respectively. Then, the "func" function is called with the variables "a" and "b" as arguments.
Inside the "func" function, the value of "x" is divided by 3 and stored back into "x". Then, the value of "x" is assigned to "y". Finally, the values of "x" and "y" are printed.
Since "a" is passed as a reference to "x" in the "func" function, any changes made to "x" will also affect the value of "a". Therefore, after the function call, the value of "a" becomes 3. However, "b" is passed by value to "y", so any changes made to "y" will not affect the value of "b". Therefore, the value of "b" remains 20.
Hence, the output of the program segment is "3 3" followed by "3 20".