Master C Data Types: From Basics to Platform‑Specific Details
This article provides a comprehensive overview of C language data types, covering basic, derived, pointer, void, and derived types, their memory sizes, value ranges, signedness, platform‑dependent variations, and related keywords such as sizeof, size_t, and fixed‑width uintX_t types.
C Language Data Types Overview
Data types are the foundation of programming languages, originally designed to let developers make efficient use of scarce memory resources. Over time they also define the range of values and permissible operations for data objects.
Determine the memory size occupied by a data object.
Define the numeric range of the data object.
Specify the operations that can be performed on the data object.
For example, a basic integer occupies 4 B, has a range of [0x0, 0xFFFFFFFF] and supports arithmetic operations.
Four Main Data Type Categories
Basic data types : integer, floating‑point, character and boolean.
Derived data types : arrays, structures, unions and enumerations.
Pointer types : store memory addresses.
Void type : represents no value, used for functions that return nothing or for generic pointers.
Derived types : const, qualifier and user‑defined types.
Basic Data Type Value Ranges
Numeric Types
Integer Types
Integers are divided into int, long and long long. Their representation can be decimal, binary (prefix 0b), octal (prefix 0) or hexadecimal (prefix 0x). Signedness and size are indicated by suffixes u (unsigned) and l (long).
85 /* decimal */
0213 /* octal */
0x4b /* hexadecimal */
30 /* integer */
30u /* unsigned integer */
30l /* long integer */
30ul /* unsigned long integer */Floating‑Point Types
Floating‑point types include float (single precision) and double (double precision). Literals can be written in decimal form or scientific notation.
double (default) : 2.3
float : 2.3f
long double : 2.3lf
3.14159 /* valid */
314159E-5L /* valid */
510E /* invalid: incomplete exponent */
210f /* invalid: missing decimal or exponent */
.e55 /* invalid: missing integer or fraction */ #include <stdio.h>
#include <float.h>
int main() {
printf("float byte: %lu
", sizeof(float));
printf("float MIN: %E
", FLT_MIN);
printf("float MAX: %E
", FLT_MAX);
printf("float DIG: %d
", FLT_DIG);
return 0;
}Character Types
Char
Char literals are enclosed in single quotes, occupy 1 B, and range from –128 to 127, matching ASCII codes. They can be ordinary characters or escape sequences.
Signed vs Unsigned
Only integer and character types have signedness. Signed types have a sign bit, giving them a different numeric range despite the same memory size. For example, signed char ranges from –128 to 127, while unsigned char ranges from 0 to 255.
CPU Platform Adaptation
The actual size of C basic data types depends on the CPU word length (32‑bit vs 64‑bit). The sizeof operator and size_t type help write portable code.
sizeof Operator
int main() {
char stringA[] = "Hello World!
";
printf("sizeof(char) = %d
", sizeof(char));
printf("sizeof(int) = %d
", sizeof(int));
printf("sizeof(long int) = %d
", sizeof(long int));
printf("sizeof(float) = %d
", sizeof(float));
printf("sizeof(double) = %d
", sizeof(double));
printf("sizeof(stringA) = %d
", sizeof(stringA)/sizeof(char));
return 0;
}size_t Type
size_tis an unsigned integer type defined by the C standard to represent the maximum size of objects on a given platform. It is typically defined as unsigned int on 32‑bit systems and unsigned long on 64‑bit systems.
typedef unsigned int size_t; // 32‑bit
typedef unsigned long size_t; // 64‑bitStandard library functions such as malloc, memcpy and strlen use size_t for size arguments.
uintX_t Types
The stdint.h header defines fixed‑width integer types like uint8_t, uint16_t, uint32_t, and uint64_t to improve portability across different CPU architectures.
uint16_t: %hu
uint32_t: %u
uint64_t: %llu
uint8_t behaves like char when printed.
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
#if __WORDSIZE == 64
typedef long int int64_t;
#else
typedef long long int int64_t;
#endif
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#if __WORDSIZE == 64
typedef unsigned long uint64_t;
#else
typedef unsigned long long uint64_t;
#endifSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
