C Data Types
C provides several built-in data types to store different kinds of values: int for whole numbers, float and double for decimals, char for single characters, and more. Choosing the right type affects both memory usage and precision.
The exact size of these types can vary by platform, but common sizes are 4 bytes for int, 4 bytes for float, 8 bytes for double, and 1 byte for char.
int a;
float b;
double c;
char d;Numeric types
int stores whole numbers, float stores single-precision decimals, and double stores double-precision decimals for greater accuracy. long and short modify the range of int.
Character and other types
char stores a single character (or small integer), and _Bool (or bool with stdbool.h) stores true/false values. The sizeof operator tells you the exact byte size on your system.
#include <stdio.h>
int main() {
int a = 5;
float b = 5.5f;
char c = 'A';
printf("%d %.1f %c\n", a, b, c);
return 0;
}5 5.5 AThree different data types are declared, initialized and printed.
#include <stdio.h>
int main() {
printf("%lu\n", sizeof(int));
return 0;
}4sizeof(int) reports the number of bytes an int occupies, typically 4.
Key points
- int, float, double and char are the core basic types.
- double has more precision than float.
- sizeof() reveals the byte size of a type on your platform.
- Type sizes can vary slightly between compilers and platforms.
