C Data Types
Primary Data Types
C provides several built-in data types. The size of each type may vary by platform, but the values below are typical for a 64-bit system.
| Type | Size | Format Specifier | Range | Description |
|---|---|---|---|---|
int | 4 bytes | %d or %i | -2,147,483,648 to 2,147,483,647 | Integer numbers |
float | 4 bytes | %f | ~3.4×10⻳⸠to 3.4×10³â¸ | Single-precision decimal |
double | 8 bytes | %lf | ~1.7×10⻳â°â¸ to 1.7×10³â°â¸ | Double-precision decimal |
char | 1 byte | %c | -128 to 127 (or 0 to 255) | Single character |
void | — | — | — | No value (used for functions/pointers) |
Type Modifiers
Type modifiers change the size or sign of a base type. They can be combined with int, char, and double.
| Type | Size | Format Specifier | Range |
|---|---|---|---|
short int | 2 bytes | %hd | -32,768 to 32,767 |
unsigned int | 4 bytes | %u | 0 to 4,294,967,295 |
long int | 4 or 8 bytes | %ld | -2,147,483,648 to 2,147,483,647 (min) |
long long int | 8 bytes | %lld | -9.2×10¹⸠to 9.2×10¹⸠|
unsigned long long | 8 bytes | %llu | 0 to 1.8×10¹⹠|
unsigned char | 1 byte | %c | 0 to 255 |
long double | 10 or 16 bytes | %Lf | Extended precision |
Derived Types
C also has derived data types that are built from primary types:
- Arrays — collection of elements of the same type
- Pointers — variables that store memory addresses
- Structures — group of variables of different types under one name
- Unions — similar to structures but share the same memory
- Functions — blocks of reusable code
#include <stdio.h>
int main() {
int age = 25;
float price = 9.99f;
double pi = 3.14159265358979;
char grade = 'A';
printf("int: %d\n", age);
printf("float: %f\n", price);
printf("double: %lf\n", pi);
printf("char: %c\n", grade);
// Printing char as integer (ASCII value)
printf("char as int: %d\n", grade); // 65
return 0;
}
/*
Output:
int: 25
float: 9.990000
double: 3.141593
char: A
char as int: 65
*/
#include <stdio.h>
int main() {
// sizeof returns the size in bytes
printf("Size of char: %zu bytes\n", sizeof(char));
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of float: %zu bytes\n", sizeof(float));
printf("Size of double: %zu bytes\n", sizeof(double));
printf("Size of long int: %zu bytes\n", sizeof(long int));
printf("Size of long long int: %zu bytes\n", sizeof(long long int));
printf("Size of unsigned int: %zu bytes\n", sizeof(unsigned int));
// Type modifiers in action
unsigned int population = 4294967295U; // max unsigned int
long long int bigNum = 9223372036854775807LL;
short int small = 32767;
printf("\nunsigned int: %u\n", population);
printf("long long int: %lld\n", bigNum);
printf("short int: %hd\n", small);
return 0;
}
/*
Output (64-bit system):
Size of char: 1 bytes
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of long int: 8 bytes
Size of long long int: 8 bytes
Size of unsigned int: 4 bytes
*/
Ready to Level Up Your Skills?
Explore 500+ free tutorials across 20+ languages and frameworks.