logo

Crowdly

Browser

Add to Chrome

In C++ we write characters to the console using global variable  std::cout that...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

In C++ we write characters to the console using global variable std::cout that encapsulates the standard output stream and is of C++ standard library type std::ostream. Here, std::cout is the fully qualified name of an object cout that is defined in namespace std.

Both C and C++ define bitwise left shift binary operator << with the syntax

lhs-integral-expression << rhs-integral-expression

to shift the bits of operand lhs-integral-expression to the left by the number of positions specified by operand rhs-integral-expression.

Class type std::ostream overloads the built-in behavior of bitwise left shift operator << to write characters representing different type of values to an output stream. Format specification, which is the first parameter of function printf is not required. Using overloaded operator << instead of function printf also allows us to write different values in a single chained statement, as in the following example:

char ch = 'c';

std::cout << "character: " << ch << std::endl;

std::endl represents a stream manipulator that inserts the end of line character into the standard output stream followed by the flushing of the standard output stream. You can keep using character '\n' as a more efficient alternative to insert a newline rather than stream manipulator endl. Inserting character '\n' into the output stream is more efficient since only a single character is inserted into the output stream without flushing the contents of the output stream's memory buffer. On the other hand, using stream manipulator endl makes C++ code portable [because we don't have to remember the newline character when a non-ASCII character set is used].

What is the result of compilation and execution of the following code? Type the exact output or type  if the code doesn't compile.

#include <iostream>

int main() {

cout << "Hello World!";

}

More questions like this

Want instant access to all verified answers on distance3.sg.digipen.edu?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome