Lesson4 Variables and Datatypes
Lesson4 Variables and Datatypes
Datatypes,
Variables and
Constant
VARIABLES
What is a variable?
data_type variable_name;
Different Datatypes
Primitive Data types
Primitive data types are the basic types of data that are built into
the C++ language.
1.int: Represents an integer (whole number).
⚬ Example: int age = 25;
2. short: Represents a short integer, typically smaller in range than
int.
⚬ Example: short temperature = 100;
3.long: Represents a long integer, typically larger in range than int.
⚬ Example: long distance = 123456789;
Primitive Data types
1.float: Single-precision floating-point type
• Example: float height = 5.9f;
1.double: Double-precision floating-point type, offering more precision
than float.
• Example: double pi = 3.141592653589793;
1.char: Represents a single character.
• Example: char grade = 'A';
1.bool: Represents a boolean value, either true or false.
• Example: bool isStudent = true;
1.String: Represents any text
Derived Data types
Derived data types are formed by combining basic data types.