A data type tells the compiler what kind of data a variable can store. It also determines the type of value that can be stored and the operations that can be performed on it.
A data type tells the compiler what kind of data a variable can store. It also determines the type of value that can be stored and the operations that can be performed on it.
A data type tells C whether a variable will store a number, character, decimal value, or another type of data.
Think about a student record: Age can be an integer, Percentage can contain decimal values, and Grade can be a character. Different types of data need different data types.
| Data Type | Used For | Example |
|---|---|---|
| int | Integer numbers | 25, -10 |
| char | A single character | 'A', '5' |
| float | Decimal numbers | 3.14 |
| double | Decimal numbers with higher precision | 12.345678 |
| void | Indicates no value or no return value | void function() |
The int data type is used to store whole numbers without a fractional part.
int age = 20;
The char data type is used to store a single character. Character values are written inside single quotation marks.
char grade = 'A';
The float data type is used to store numbers that contain a decimal or fractional part.
float percentage = 82.5;
The double data type is used for floating-point
values when more precision is required than a typical
float.
double pi = 3.1415926535;
The void type represents the absence of a value. It is commonly used with functions that do not return a value.
void display()
A variable is declared by writing its data type followed by the variable name.
| Type | Remember |
|---|---|
| int | Whole numbers |
| char | Single character |
| float | Decimal values |
| double | Decimal values with higher precision |
| void | No value / no return value |
int?char?float and double?void?Watch a beginner-friendly explanation of basic data types in C.
A short handwritten-style revision sheet for C data types will be provided here.
Use the mind map for quick revision of basic C data types.