C++ Boolean Data Types
Boolean Types A boolean data type is declared with the bool keyword and can only take the values true or false. When the value is returned, true = 1 and false = 0. Example bool isCodingFun = true; bool isFishTasty…
Boolean Types A boolean data type is declared with the bool keyword and can only take the values true or false. When the value is returned, true = 1 and false = 0. Example bool isCodingFun = true; bool isFishTasty…
Numeric Types Use int when you need to store a whole number without decimals, like 35 or 1000, and float or double when you need a floating point number (with decimals), like 9.99 or 3.14515.
C++ Data Types As explained in the Variables article , a variable in C++ must be a specified data type: Example int myNum = 5; // Integer (whole number) float myFloatNum = 5.99; // Floating point number double myDoubleNum =…
C++ User Input You have already learned that cout is used to output (print) values. Now we will use cin to get user input. cin is a predefined variable that reads data from the keyboard with the extraction operator (>>).…
Real-Life Examples Let’s get a bit more practical! Often in our examples, we simplify variable names to match their data type (myInt or myNum for int types, myChar for char types, and so on). This is done to avoid confusion.…
Constants When you do not want others (or yourself) to change existing variable values, use the const keyword (this will declare the variable as “constant”, which means unchangeable and read-only): Example const int myNum = 15; // myNum will always…
C++ Identifiers All C++ variables must be identified with unique names. These unique names are called identifiers. Identifiers can be short names (like x and y) or more descriptive names (age, sum, totalVolume). Note: It is recommended to use descriptive…
Declare Many Variables To declare more than one variable of the same type, use a comma-separated list: Example int x = 5, y = 6, z = 50; cout << x + y + z;
C++ Variables Variables are containers for storing data values. In C++, there are different types of variables (defined with different keywords), for example: int – stores integers (whole numbers), without decimals, such as 123 or -123 double – stores floating…