Variables and Data Types in C
📘 C
👁 36 views
📅 Dec 22, 2025
⏱ Estimated reading time: 2 min
A variable is a named memory location used to store data that can be changed during program execution.
Rules for Naming Variables
-
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
Declaration of Variables
Initialization of Variables
Types of Variables
-
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 in C
Data types specify the type of data a variable can store.
Classification of Data Types
1. Basic (Primary) Data Types
| Data Type | Description |
|---|---|
int | Integer values |
float | Decimal values |
double | Double precision decimals |
char | Single character |
2. Derived Data Types
-
Arrays
-
Pointers
-
Structures
-
Unions
3. Enumeration Data Type
4. Void Data Type
-
Represents no value
Size of Data Types (Typical)
| Data Type | Size |
|---|---|
char | 1 byte |
int | 2 or 4 bytes |
float | 4 bytes |
double | 8 bytes |
Example Program
Summary
-
Variables store data values
-
Data types define the kind of data
-
C supports multiple data types
-
Proper declaration is mandatory
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials