Introduction To C Plus Plus - Study Mode

[#106] What is the output of the following code: int x = 5, y = 2
cout << x / y
in C++?
Correct Answer

(D) 2

[#107] What is the correct syntax to define a class named 'Rectangle' with private member variables 'length' and 'width' in C++?
Correct Answer

(D) class Rectangle { private: int length, width }

[#108] What is the output of the following code: cout << "Hello
World"
in C++?
Correct Answer

(A) Hello World

Explanation

Solution: Let's break down this C++ code snippet! The code is: cout << "Hello
World"
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
World" . The important part here is
. This is a special character called a newline character .
tells the program to move the cursor to the beginning of the next line. So, "Hello
World" 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 '
' 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

[#109] What will be the output of the following C++ code? #include <iostream>
int const s=9
int main()
{
std::cout << s
return 0
}
Correct Answer

(A) 9

[#110] What will be the output of the following C++ code? #include <iostream>

int main(int argc, char const *argv[])
{
cout<<"Hello World"
return 0
}
Correct Answer

(A) Hello World

Explanation

Solution: The given code is a basic C++ program that prints a message to the console. It includes the <iostream> header , which allows the use of input and output streams like cout . The main function is defined correctly with appropriate parameters ( int argc, char const *argv[] ), though these parameters are not used. cout<<"Hello World"
correctly outputs the text "Hello World" to the standard output. There are no syntax or runtime errors in the code , and it will compile and run successfully. Therefore, the output will be: Hello World