Definition
📌 Data Types
C has a small set of built-in (primitive) data types that describe what kind of value a variable can hold, and how much memory it uses.The exact size of a type can vary slightly by system, but the common sizes on most modern platforms are shown below..
Syntax
syntax
int wholeNumber;
float singlePrecision;
double doublePrecision;
char singleCharacter;Example
c
#include <stdio.h>
int main() {
printf("int: %zu bytes\n", sizeof(int));
printf("float: %zu bytes\n", sizeof(float));
printf("double: %zu bytes\n", sizeof(double));
printf("char: %zu bytes\n", sizeof(char));
return 0;
}Output
outputint: 4 bytes
float: 4 bytes
double: 8 bytes
char: 1 bytes
Important Points
intstores whole numbers (typically 4 bytes).floatanddoublestore decimal numbers;doubleis more precise.charstores a single character (1 byte), stored internally as a number (ASCII code).- Add
unsignedbefore a type to store only non-negative numbers with a larger positive range.
Common Mistakes
- Assuming type sizes are identical on every system — always confirm with
sizeof()for portable code. - Losing decimal precision by storing a
float/doubleresult into anint. - Comparing
float/doublevalues with==— precision errors can make this unreliable.
Interview Tip
🎯 Before your interview
A classic interview question: "why prefer double over float?" — double has roughly twice the precision, at the cost of more memory.
