Variables and Data Types
Introduction to C
Structure of a C Program
Variables and Data Types
Input and Output
Operators in C
Decision Making
If Statement
if...else Statement
Nested if Statement
Nested if...else Statement
Switch Statement
Loops
For Loop
While Loop
Do While Loop
Loop Comparison
Arrays
Strings
Functions
Function Types
Library Functions
User-Defined Functions
Recursion Function
Pointers
Structures
File Handling
Common Mistakes
Ideas
Variables and Data Types
In C, variables act as containers for storing data. Data types specify the size and type of information the variable can hold, such as integers, characters, or decimal numbers.
Common Data Types in C
| Data Type | Keyword | Example Value |
|---|---|---|
| Integer | int |
20, -5 |
| Floating Point | float |
5.8, 3.14 |
| Character | char |
'A', '$' |
Practical Example
#include <stdio.h> int main() { int age = 20; // Integer type float height = 5.8; // Decimal type char grade = 'A'; // Character type printf("Age: %d\n", age); printf("Height: %.1f\n", height); printf("Grade: %c\n", grade); return 0; }
Key Points for Success
- Declaration: A variable must be declared (created) before you can use it.
- Case-Sensitivity: C is strict—
ageandAgeare seen as two completely different variables. - Readability: Use descriptive names (like
userAgeinstead ofa) to make your code easier to maintain.
Example
Executing...
❌ Error:
✅ Output:
// Click Run ▶ to execute
🏋️ Test Yourself With Exercises
Take our quiz on Variables and Data Types to test your knowledge.
Browse Quizzes »