The C language is a programming language used in a wide range of applications, including embedded systems and system programming. Among these, “data types” and “sizes” have a major impact on a program’s memory usage and performance. Especially when running programs in different environments (32bit / 64bit, Windows / Linux, etc.), the size of data types can vary, making it important to choose the correct type. In this article, we will explain the sizes of basic C data types, differences across environments, and key points for selecting appropriate types. We also introduce practical information such as how to use the sizeof operator and how to leverage fixed-width integer types (stdint.h). This will deepen your understanding of C types and enable more efficient programming.
2. Basic Data Types and Sizes in C
2.1 Integer Types Size List
Data Type
32‑bit environment
64‑bit environment
Minimum size
char
1 byte
1 byte
1 byte
short
2 bytes
2 bytes
2 bytes
int
4 bytes
4 bytes
2 bytes
long
4 bytes
8 bytes
4 bytes
long long
8 bytes
8 bytes
8 bytes
2.2 Floating‑Point Types Size List
Data Type
32‑bit environment
64‑bit environment
float
4 bytes
4 bytes
double
8 bytes
8 bytes
long double
8–16 bytes
16 bytes
3. Platform-Dependent Data Type Sizes
3.1 Differences in Size by OS and Compiler
Data Type
Windows (LLP64)
Linux (LP64)
32-bit Environment
int
4 bytes
4 bytes
4 bytes
long
4 bytes
8 bytes
4 bytes
long long
8 bytes
8 bytes
8 bytes
4. Verify data type sizes with the sizeof operator
4.1 Basics of sizeof
#include <stdio.h>
int main() {
printf("Size of int: %zu bytesn", sizeof(int));
printf("Size of double: %zu bytesn", sizeof(double));
return 0;
}
5. Fixed-width integer types (using stdint.h)
#include <stdio.h>
#include <stdint.h>
int main() {
int8_t a = 100;
uint16_t b = 50000;
int32_t c = -123456;
uint64_t d = 1000000000ULL;
printf("Size of int8_t: %zu bytesn", sizeof(a));
printf("Size of uint16_t: %zu bytesn", sizeof(b));
printf("Size of int32_t: %zu bytesn", sizeof(c));
printf("Size of uint64_t: %zu bytesn", sizeof(d));
return 0;
}
6. Struct Size and Alignment
6.1 Struct Memory Layout
#include <stdio.h>
struct example {
char a;
int b;
double c;
};
int main() {
printf("Size of struct: %zu bytesn", sizeof(struct example));
return 0;
}
7. Choosing Appropriate Data Types
7.1 Choosing Integer Types
Data Type
Size
Range
int8_t
1B
-128 – 127
uint8_t
1B
0 – 255
int32_t
4B
approximately -2.1B – 2.1B
uint32_t
4B
0 – 4.2B
8. FAQ (Frequently Asked Questions)
Q1: Why is the result of sizeof a unsigned int?
A: In C, the return value of sizeof is of type size_t, which is an unsigned integer type. Because a negative size cannot exist, it is defined as a safe type.
size_t size = sizeof(int);
printf("Size of int: %zu bytesn", size);
9. Summary
9.1 Key Points of This Article
✅ Data type sizes are platform-dependent ✅ Use sizeof to check the actual size ✅ Leverage fixed-width integer types ✅ Struct sizes are affected by memory alignment ✅ Choosing the appropriate data type