0
0
C++programming~5 mins

Basic formatting in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of std::cout in C++?

std::cout is used to print output to the console (screen). It helps us show messages or results to the user.

Click to reveal answer
beginner
How do you print a new line in C++ using std::cout?

You can print a new line by using \n inside the string or by using std::endl after the output.

Click to reveal answer
beginner
What does this code print?<br>
std::cout << "Hello" << " " << "World!" << std::endl;

This prints: Hello World! followed by a new line.

Click to reveal answer
intermediate
What is the difference between \n and std::endl in C++ output?

\n adds a new line character but does not flush the output buffer immediately.<br>std::endl adds a new line and also flushes the output buffer, making sure output appears right away.

Click to reveal answer
beginner
How can you print variables with text in C++ using std::cout?

You can use the insertion operator << to combine text and variables. For example:<br>int age = 25;<br>std::cout << "Age: " << age << std::endl;

Click to reveal answer
Which of these prints a new line in C++?
Astd::cout << "\n";
Bstd::cout << "newline";
Cstd::cout << "\t";
Dstd::cout << "space";
What does std::endl do besides adding a new line?
AAdds a tab space
BFlushes the output buffer
CEnds the program
DStarts a new program
How do you print the value of an integer variable num with text?
Astd::cout << "Number: " << num << std::endl;
Bprint("Number: " + num);
Cecho "Number: " num;
Dcout << num + "Number";
What symbol is used to send output to the console in C++?
A==
B>>
C<<
D//
Which line correctly prints "Hello World!" followed by a new line?
Aprint("Hello World!\n");
Bstd::cout >> "Hello World!";
Cecho "Hello World!";
Dstd::cout << "Hello World!" << std::endl;
Explain how to print text and variables together in C++ using std::cout.
Think about how you join strings and numbers in one output line.
You got /4 concepts.
    Describe the difference between using \n and std::endl for new lines in C++ output.
    Consider what happens behind the scenes when output is shown.
    You got /3 concepts.