filmov
tv
Lecture 3 (Variables and Data type)
Показать описание
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 point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
string - stores text, such as "Hello World". String values are surrounded by double quotes
bool - stores values with two states: true or false
To create a variable, you must specify the data type and assign it a value:
Syntax
-------------------------------------------
data type variable = value;
-------------------------------------------
C++ Comments
Comments can be used to explain C++ code, and to make it more readable. It can also be used to prevent execution when testing alternative code. Comments can be singled-lined or multi-lined.
--------------------------------------------------------------------------------------------
Single-line comments start with two forward slashes (//).
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Multi-line comments start with /* and ends with */.
Any text between /* and */ will be ignored by the compiler
--------------------------------------------------------------------------------------------
int - stores integers (whole numbers), without decimals, such as 123 or -123
double - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
string - stores text, such as "Hello World". String values are surrounded by double quotes
bool - stores values with two states: true or false
To create a variable, you must specify the data type and assign it a value:
Syntax
-------------------------------------------
data type variable = value;
-------------------------------------------
C++ Comments
Comments can be used to explain C++ code, and to make it more readable. It can also be used to prevent execution when testing alternative code. Comments can be singled-lined or multi-lined.
--------------------------------------------------------------------------------------------
Single-line comments start with two forward slashes (//).
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
Multi-line comments start with /* and ends with */.
Any text between /* and */ will be ignored by the compiler
--------------------------------------------------------------------------------------------