Challenge - 5 Problems
Cout Output Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of chained cout statements
What is the output of this C++ code?
C++
#include <iostream> int main() { std::cout << "Hello" << ", " << "World!" << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Look at how the strings and commas are chained with << operators.
✗ Incorrect
The code prints the strings exactly as chained with <<, so it outputs 'Hello, World!' followed by a newline.
❓ Predict Output
intermediate2:00remaining
Output with multiple cout lines
What will be printed when this code runs?
C++
#include <iostream> int main() { std::cout << "Line 1" << std::endl; std::cout << "Line 2"; std::cout << " Line 3" << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Check where std::endl is used to add new lines.
✗ Incorrect
The first cout ends with std::endl adding a newline. The second cout prints without newline, so the third cout continues on the same line and ends with std::endl.
❓ Predict Output
advanced2:00remaining
Output with mixed data types using cout
What is the output of this code snippet?
C++
#include <iostream> int main() { int a = 5; double b = 3.2; std::cout << "a = " << a << ", b = " << b << std::endl; return 0; }
Attempts:
2 left
💡 Hint
By default, double prints with minimal decimals unless formatted.
✗ Incorrect
The double value prints as 3.2 by default without extra trailing zeros.
❓ Predict Output
advanced2:00remaining
Output with cout and escape sequences
What will this program print?
C++
#include <iostream> int main() { std::cout << "First Line\nSecond Line\tTabbed" << std::endl; return 0; }
Attempts:
2 left
💡 Hint
Escape sequences like \n and \t create new lines and tabs in output.
✗ Incorrect
The \n creates a new line and \t adds a tab space in the output.
❓ Predict Output
expert2:00remaining
Output of cout with pointer and address
What is the output of this code?
C++
#include <iostream> int main() { int x = 10; int* p = &x; std::cout << "Value: " << *p << ", Address: " << p << std::endl; return 0; }
Attempts:
2 left
💡 Hint
The pointer prints the memory address, which looks like a hex number starting with 0x.
✗ Incorrect
The *p dereferences the pointer to print the value 10, and p prints the memory address in hexadecimal format.