Lesson 2 of 24

Variables, auto and string

8 min 20 XP

C++ adds bool (true/false) and string (text), so no more C char-array headaches. With auto the compiler works out the type for you.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

A bool prints as 1/0 by default; boolalpha prints true/false. For decimal places use fixed << setprecision(2) from <iomanip>.

Challenge

+20 XP

Store "C++" in a string course and 40 in an int hours, then print: Course: C++ Hours: 40

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.