C++ Basics
Short drills to make the concepts stick — predict what code prints, fix a broken snippet, or write a small function. Commit to an answer before you run anything.
1.4 — Variable Assignment and Initialization
What does this print?
Read the initialization line closely before choosing an answer.
#include <iostream>
int main()
{
int a, b = 5;
std::cout << a + b << '\n';
return 0;
}What does this print?
Think about what happens when a double value is stored in an int variable using copy-initialization.
#include <iostream>
int main()
{
int x = 4.5;
std::cout << x << '\n';
return 0;
}Fix the uninitialized variable
The function should return a + 5, but the tests all fail. Find and fix the bug.
Edit student.cpp, then Run to check it against the tests.
1.9 — Introduction to Literals and Operators
Fix the integer arithmetic order
The function should return a percentage like percent(3, 4) == 75, but most cases return 0. Find the operator-ordering bug.
Edit student.cpp, then Run to check it against the tests.
1.10 — Introduction to Expressions
Compute a perimeter inline
Implement the function body using a single return statement with an inline arithmetic expression — no extra variables needed.
Edit student.cpp, then Run to check it against the tests.