Data Type Categories
Integer Family
Unsigned data types utilize all bits for value storage.
Floating-Point Family
Composite Types
Other Types
Arrays can modify they element types and sizes as needed.
Integer Storage in Memory
Original, Inverse, and Complement Codes
Original code represents the true value of data. Integers are stored as complement code binary sequences in memory, while memory windows display hexadecimal values.
Conversion between complement and original codes follows these rules:
- Complement → Original: Invert all bits except sign bit, then add 1
- Original → Complement: Invert all bits except sign bit, then add 1
Endianness
Endianness refers to byte ordering in memory and is hardware-dependent. For single-byte data, byte order is irrelevant.
Detecting endianness programmatically:
int check_endian() {
int test = 1;
return *(char*)&test == 1 ? 1 : 0; // Returns 1 for little-endian
}
Practical Examples
int main() {
signed char sc = -1;
unsigned char uc = -1;
printf("Signed: %d, Unsigned: %d", sc, uc);
return 0;
}
Data truncation occurs during storage. Type promosion happens during usage (e.g., char/short promoted to int in expresssions).
Promotion rules:
- Signed types: Extend sign bit
- Unsigned types: Zero-extend
int main() {
char val = -128;
printf("Unsigned: %u\nSigned: %d", val, val);
return 0;
}
When mixing signed and unsigned operations, signed values convert to unsigned.
Floating-Point Storage
Storage Representation
Float literals with 'f' suffix are single-precision, others are double-precision.