1.
The basic commands that a computer performs are ____, and performance of arithmetic and logical operations.
Correct Answer
B. Input, output, storage
Explanation
The basic commands that a computer performs are input, output, and storage. Input refers to the process of receiving data or instructions from external sources, such as a keyboard or mouse. Output involves displaying or transmitting data or results to external devices, such as a monitor or printer. Storage refers to the ability of a computer to store and retrieve data and instructions for later use. These three commands are fundamental to the functioning of a computer system.
2.
A program called a(n) ____ translates instructions written in high-level languages into machine code.
Correct Answer
C. Compiler
Explanation
A compiler is a program that takes instructions written in high-level languages and translates them into machine code. It analyzes the entire program, checking for errors and translating the code into a form that can be understood by the computer's processor. Unlike an assembler, which translates assembly language into machine code, a compiler works with higher-level languages like C, C++, or Java. A decoder is not responsible for translating high-level languages, and a linker is used to combine object files into an executable program. Therefore, a compiler is the correct answer for this question.
3.
Suppose that x is an int variable. Which of the following expressions always evaluates to true?
Correct Answer
A. (x > 0) || ( x <= 0)
Explanation
The expression (x > 0) || (x <= 0) will always evaluate to true for any integer x. This is because the logical OR (||) operator ensures that if at least one of the conditions is true, the entire expression is true. Since any integer x will either be greater than 0 or less than or equal to 0, this condition covers all possible integer values.
The other expressions have conditions that can never be true simultaneously (such as x > 0 and x <= 0 both being true at the same time), so they do not always evaluate to true.
4.
Which of the following expressions correctly determines that x is greater than 10 and less than 20?
Correct Answer
D. 10 < x && x < 20
Explanation
The expression "10 < x && x < 20" correctly determines that x is greater than 10 and less than 20. The "&&" operator is the logical AND operator, which means both conditions must be true for the overall expression to be true. In this case, the first condition "10 < x" checks if x is greater than 10, and the second condition "x < 20" checks if x is less than 20. Only if both conditions are true, the expression will be true, indicating that x is within the desired range.
5.
What is the output of the following C++ code?
int x = 35;
int y = 45;
int z;
if (x > y)
z = x + y;
else
z = y – x;
cout << x << " " << y << " " << z << endl;
Correct Answer
C. 35 45 10
Explanation
The code initializes variables x and y with the values 35 and 45 respectively. It then checks if x is greater than y. Since 35 is not greater than 45, the else block is executed. In the else block, z is assigned the value of y minus x, which is 45 - 35 = 10. Finally, the values of x, y, and z are printed, resulting in the output "35 45 10".
6.
Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z = 7, and w = 1;
What is the output of the following statement?
cout << " x == y : " << (x == y ) << endl;
Correct Answer
A. X == y: 0
Explanation
The output of the statement is "x == y: 0". This is because the expression (x == y) evaluates to false, since the value of x (3) is not equal to the value of y (4). In C++, when a comparison is true, it is represented as 1, and when it is false, it is represented as 0. Therefore, the output is 0.
7.
Suppose that x, y, z, and w are int variables, and x = 3, y = 4, z = 7, and w = 1;
What is the output of the following statement?
cout << " ! (z > w ) : " << ! (z > w ) << endl;
Correct Answer
D. ! (z > w): 0
Explanation
The output of the statement is " ! (z > w) : 0". This is because the expression "(z > w)" evaluates to true (1) since 7 is greater than 1. The "!" operator negates the result, so it becomes false (0). The statement then outputs the string " ! (z > w) : " followed by the result of the expression, which is 0.
8.
The type of error in the following statement is :
int a=b/0 // b is defined as int
Correct Answer
C. Run-time error
Explanation
The given statement will result in a run-time error because it is trying to divide a number by zero. In programming, dividing by zero is not allowed and will cause an error during the execution of the program.
9.
The driver function of a C++ program that if it is not present in a program, no execution can take place:
Correct Answer
A. Main
Explanation
The driver function of a C++ program is the main function. It is the entry point of the program where the execution starts. Without the main function, the program cannot be executed as there would be no starting point for the program to begin execution. Therefore, if the main function is not present in a C++ program, no execution can take place.
10.
What is the output of the following code :
int main()
{ int a=4 ;
(a>0)? cout<< " Number is positive " : cout<< " Number is negative " ;
return 0 ;
}
Correct Answer
C. Number is positve
Explanation
The output of the code will be "Number is positive". This is because the code uses the ternary operator "?:" to check if the value of variable "a" is greater than 0. If it is true, it will print "Number is positive", otherwise it will print "Number is negative". In this case, since the value of "a" is 4 which is greater than 0, the condition is true and "Number is positive" will be printed.
11.
What is the output of the following code :
int main()
{ int num = 9;
if (num<0);
num= -num ;
return o ;
}
Correct Answer
D. Syntax error
Explanation
The key points to note are:
The if (num < 0); line has a semicolon at the end, which terminates the if statement. This means that the subsequent line num = -num; will execute regardless of the if condition.
As a result, num will be assigned the value -num, making num negative.
However, there is a mistake in the return statement: return o; should be return 0;. Assuming this is a typographical error and should be corrected to return 0;, the program will compile and run, but since there are no cout statements to display output, the program's output will not show any value in a typical run.
12.
The output of the following code is :
int main()
{ int n=17 ;
cout << ( n == 16 ) << endl ;
return 0 ;
}
Correct Answer
B. 0
Explanation
The code is checking if the value of n is equal to 16. Since n is initialized as 17, the condition (n == 16) evaluates to false. The false value is then printed to the console using the cout statement. In C++, false is represented as 0. Therefore, the output of the code is 0.
13.
A C++ code line ends with?
Correct Answer
A. A Semicolon (;)
Explanation
In C++, a code line is terminated with a semicolon (;). This is a fundamental rule in the C++ programming language. The semicolon is used to indicate the end of a statement or expression. It is necessary to include a semicolon at the end of each line of code to ensure proper syntax and to separate different statements or expressions within the code.
14.
What is the output of the following code:
int main()
{
int x=7 ;
if ( x=8) cout << x-1 ;
else cout << x+1 ;
return 0 ;
}
Correct Answer
C. 7
Explanation
The output of the code is 7. In the if statement, the condition x=8 is used instead of x==8. This is an assignment operator, not a comparison operator. As a result, the value of x is set to 8. Since the condition is true, the code inside the if statement is executed, which is cout << x-1. Therefore, the output is 7.
15.
What is the output of the following code:
int main ()
{ int x=2 , y ;
//x=x*2 ;
y=x++ ;
cout << "x= " << x << "\ty=" << y ;
return 0 ;
}
Correct Answer
B. X = 3 y = 2
Explanation
The code starts by initializing the variable x to 2. Then, the line "y = x++" assigns the value of x to y and then increments the value of x by 1. After that, the code prints the values of x and y using the "cout" statement. Since x was incremented by 1 before printing, its value is 3. The value of y remains 2 because it was assigned the value of x before it was incremented. Therefore, the output of the code is "x = 3 y = 2".
16.
What is the output of the following code:
int main()
{ int a=98 ; double b=5 ;
cout << a/3.0 ;
return 0 ;
}
Correct Answer
A. 32.6667
Explanation
In the expression a/3.0, the value of a is an integer (98) and the value of 3.0 is a double. When performing arithmetic operations with operands of different types, C++ promotes the operands to the highest data type involved in the operation, which in this case is double. Therefore, the division operation will be performed using double arithmetic, resulting in the decimal value 32.6667.
17.
Which of the following is a unary operator?
Correct Answer
B. ++
Explanation
The correct answer is ++. A unary operator is an operator that operates on a single operand. In this case, the ++ operator is a unary operator because it increments the value of the operand by 1.
18.
Which of the following is not a relational operator in the C++ program?
Correct Answer
A. =
Explanation
The equal sign (=) is not a relational operator in C++. It is actually an assignment operator used to assign a value to a variable. Relational operators are used to compare values and return a boolean result, such as whether one value is equal to another (==) or greater than or equal to another (>=).
19.
C++ program may have more than one main function?
Correct Answer
B. False
Explanation
A C++ program cannot have more than one main function. The main function is the entry point of the program, and there can only be one entry point. Having multiple main functions would lead to ambiguity and confusion in the program's execution. Therefore, it is false that a C++ program may have more than one main function.
20.
Which of the following is not a standard data type ?
Correct Answer
D. Data
Explanation
The given options include three standard data types: int, char, and float. However, "data" is not a standard data type in most programming languages. It is a generic term that can refer to any type of information, but it is not a specific data type like int, char, or float. Therefore, "data" is the correct answer as it is not a standard data type.
21.
The output of the following code is : int main() { float x=1 ; cout << ( x == 3.0 / 7.0 + 2.0 / 7.0 + 2.0 / 7.0 ) ; return 0 ; }
Correct Answer
D. None of above
Explanation
The output of the code will be "false" or "0". This is because the expression (3.0 / 7.0 + 2.0 / 7.0 + 2.0 / 7.0) evaluates to a value slightly less than 1.0 due to the limitations of floating-point precision. When comparing this value to the float variable x, which is initialized to 1.0, the result is false. Therefore, the correct answer is "none of above".
22.
Which of the following is illegal identifier ?
Correct Answer
D. Return
Explanation
The identifier "return" is illegal because it is a reserved keyword in many programming languages, including C++, Java, and Python. Reserved keywords are predefined and have special meanings in the language, so they cannot be used as identifiers for variables, functions, or other entities in the program.