- 01Getting Started
- 02Your First Output (cout)
- 03Variables and Types (int/double/string/bool)
- 04Conditionals (if statements)
- 05Loops (for statements)
- 06Writing a Function
- 07Working with Arrays
- 08Loops (while statements)
- 09Pointer Basics
- 10References
- 11Classes (Object-Oriented Programming)
- 12Constructors and Destructors
- 13Inheritance
- 14Using vector (the Standard Library)
- 15String Manipulation (string)
- 16Structs (struct)
- 17Error Handling (try/catch)
- 18The Ternary Operator
- 19The switch Statement
- 20[Applied] Build a Mini Inventory Management System
Variables and Types (int/double/string/bool)
This lesson covers declaring variables using C++'s basic types โ int, double, string, and bool. It's for anyone searching "C++ variable type."
C++ is a statically typed language, meaning you have to specify a type when declaring a variable. The main types are int (integer), double (decimal), std::string (text), and bool (true/false).
The example declares two variables, std::string name = "Alice"; and int age = 14;, and outputs them chained together with cout.
A common early mistake is not realizing you need #include <string> to use std::string. Unlike C's string handling (a char array), C++'s std::string is a convenient type that makes resizing and concatenation easy.
In real projects, choosing the right type for the kind of data you're handling lets you fine-tune both memory usage and processing speed.
๐งช This site can't compile or run C++ directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
