A variable is a named memory location used to store data whose value can change during program execution.
Must begin with a letter or underscore (_)
Cannot start with a number
No spaces or special symbols
Keywords cannot be used as variable names
C++ is case-sensitive (Age and age are different)
Data types specify the type and size of data a variable can store.
| Data Type | Description | Example |
|---|---|---|
| int | Stores integers | int a = 5; |
| float | Stores decimal values | float b = 3.14; |
| double | Stores large decimal values | double c = 3.14159; |
| char | Stores a single character | char d = 'A'; |
| bool | Stores true or false | bool e = true; |
| void | No value | Used in functions |
Derived from basic data types.
Array
Pointer
Function
Reference
Example:
Created by the programmer.
struct
union
enum
typedef
class
Example:
Used to modify basic data types.
short
long
signed
unsigned
Example:
Value cannot be changed.
Variables store data values
Data types define memory size and operations
Correct data type selection improves efficiency
Constants protect fixed values
Variables and data types are fundamental concepts in C++ that help store, manage, and manipulate data efficiently in a program.
Take quizzes related to this topic and see where you stand!
Start Quiz Now