Topic 3| Data Types and Variables
Data Types and Variables
Data Types
Variables
Coding Example
1
, Topic 3| Data Types and Variables
Data Types in C++:
The data type specifies the size and type of information the variable will store:
Int 4bytes Stores whole numbers
float 4bytes Stores fractional numbers(up to 7 decimal
digits)
double 8 bytes Stores fractional numbers(up to 15 decimal
digits)
boolean 1 byte Stores 1 or 0 (true or false)
char 1 byte Stores single character/ letter/ number.
short 2 byte Stores short integers
Variables in C++:
Variables are containers for storing data values. Variable’s name can consist of any combination
of upper and lowercase letter, underscores and digits, but a variable name cannot begin with a
digit.
For example:
Name
dateOfBirth
my_name
Variable name should not match with any of the keyword. Keywords are predefined words that
have special meanings to the compiler.
Variable Declaration:
int a;
Variable Initialization:
Syntax:
type variable= value;
Examples:
int a = 1;
char var = ‘a’;
2
Data Types and Variables
Data Types
Variables
Coding Example
1
, Topic 3| Data Types and Variables
Data Types in C++:
The data type specifies the size and type of information the variable will store:
Int 4bytes Stores whole numbers
float 4bytes Stores fractional numbers(up to 7 decimal
digits)
double 8 bytes Stores fractional numbers(up to 15 decimal
digits)
boolean 1 byte Stores 1 or 0 (true or false)
char 1 byte Stores single character/ letter/ number.
short 2 byte Stores short integers
Variables in C++:
Variables are containers for storing data values. Variable’s name can consist of any combination
of upper and lowercase letter, underscores and digits, but a variable name cannot begin with a
digit.
For example:
Name
dateOfBirth
my_name
Variable name should not match with any of the keyword. Keywords are predefined words that
have special meanings to the compiler.
Variable Declaration:
int a;
Variable Initialization:
Syntax:
type variable= value;
Examples:
int a = 1;
char var = ‘a’;
2