A variable is a named memory location used to store data that can be changed during program execution.
Must begin with a letter or underscore _
Can contain letters, digits, and underscores
Cannot start with a digit
Cannot use C keywords
Case-sensitive
Valid: count, _total, sum1
Invalid: 1num, float, total-value
Local Variables – Declared inside a function
Global Variables – Declared outside all functions
Static Variables – Retain value between function calls
Automatic Variables – Default local variables
Data types specify the type of data a variable can store.
| Data Type | Description |
|---|---|
int | Integer values |
float | Decimal values |
double | Double precision decimals |
char | Single character |
Arrays
Pointers
Structures
Unions
Represents no value
| Data Type | Size |
|---|---|
char | 1 byte |
int | 2 or 4 bytes |
float | 4 bytes |
double | 8 bytes |
Variables store data values
Data types define the kind of data
C supports multiple data types
Proper declaration is mandatory
Take quizzes related to this topic and see where you stand!
Start Quiz Now