Constants and Strings
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.
5.3 — Numeral systems (decimal, binary, hexadecimal, and octal)
Sticky hex manipulator
Both a and b are ordinary ints. What does this program print?
#include <iostream>
int main()
{
int a { 255 };
int b { 16 };
std::cout << std::hex << a << '\n';
std::cout << b << '\n';
return 0;
}Octal literal masquerading as decimal
The function is supposed to classify codes below 100 as "small" and codes 100 or above as "large", but the threshold is wrong. Find the bug.
Edit student.cpp, then Run to check it against the tests.
5.6 — Constexpr variables
constexpr with a non-constexpr function
What happens when you compile this program?
#include <iostream>
int getMax() { return 100; }
int main()
{
constexpr int limit { getMax() };
std::cout << limit << '\n';
return 0;
}5.7 — Introduction to std::string
Fix the name-builder
The function is supposed to return "First Last" but produces only the last name. Find and fix the single-character mistake.
Edit student.cpp, then Run to check it against the tests.
5.8 — Introduction to std::string_view
Build a badge label with constexpr and string_view
Implement badgeLabel and badgeLabelLength using the provided constexpr prefix constant and std::string_view parameters.
Edit student.cpp, then Run to check it against the tests.