ExamVeda
Login
Home
31
Which of the following is the correct syntax for declaring a pointer to an integer in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
32
What is the output of the following code: cout << (5 < 2) ? "True" : "False"; in C++?
Discuss
Answer & Solution
Answer: Option A
Solution:
The expression used in the code is: cout << (5 < 2) ? "True" : "False";

This line appears to use the ternary conditional operator, but due to the missing parentheses around the conditional expression, the actual precedence rules of C++ affect the output.

In C++, the insertion operator << has higher precedence than the ternary operator ?:.

So, the expression is interpreted as: (cout << (5 < 2)) ? "True" : "False";

Here, 5 < 2 evaluates to false (i.e., 0)

So, cout << 0 is executed, which prints 0

Then the ternary operator evaluates 0 ? "True" : "False", which returns "False", but the result is not used or printed

Thus, the final output is: 0

Since "0" is not among the options but option C says 5, this indicates the question or options may be inconsistent

However, assuming the intention was to demonstrate operator precedence, the correct output should be: 0, not 5.

But given the provided options, none match this expected behavior correctly

So, the correct answer should actually be: None of the above, but if we must choose, Option C is incorrect
33
In C++, what is the purpose of the 'endl' manipulator?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
34
What is the result of the expression: sizeof(char) in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
35
What does the 'const' keyword signify when used with a member function in a C++ class declaration?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
36
Which operator is used to dereference a pointer in C++?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
37
What is the correct way to include the C++ standard input/output library header file in a C++ program?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
38
What is the output of the following code: int x = 5, y = 2; cout << x / y; in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
39
What is the correct syntax to define a class named 'Rectangle' with private member variables 'length' and 'width' in C++?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
40
What is the output of the following code: cout << "Hello\nWorld"; in C++?
Discuss
Answer & Solution
Answer: Option A
Solution:
Let's break down this C++ code snippet!
The code is: cout << "Hello\nWorld";
cout is used to display output on the screen.
The double quotes " " enclose a string of characters that will be printed.
Inside the string, we have "Hello\nWorld".
The important part here is \n. This is a special character called a newline character.
\n tells the program to move the cursor to the beginning of the next line.
So, "Hello\nWorld" means print "Hello", then move to the next line, and then print "World".
Therefore, the correct output is "Hello" on one line and "World" on the next line.
Option B and C are incorrect because they only output one word.
Option D is incorrect because it prints the actual '\n' character, rather than interpreting it as a newline.
The correct answer is to imagine the output with Hello appearing above World.
So, the best way to visualize this output is :
Hello
World