C Extended Data Types
In this page:
What are Extended Data Types?
Extended data types combine a base type like int or char with modifiers -- short, long, signed, and unsigned -- that adjust its size, range, or whether it can represent negative values.
Example: What are Extended Data Types?
#include <stdio.h>
int main() {
unsigned short small = 100;
printf("%hu", small);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
short and long Modifiers
The short and long modifiers adjust an integer type's typical size: short usually uses fewer bytes for a smaller range, while long usually uses more bytes to accommodate a wider range of values.
Example: short and long Modifiers
#include <stdio.h>
int main() {
short s = 100;
long l = 1000000L;
printf("%hd %ld", s, l);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
signed and unsigned Modifiers
The signed and unsigned modifiers control whether an integer type can represent negative numbers: signed splits its range between negative and positive values, while unsigned dedicates the entire range to positive values and zero.
Example: signed and unsigned Modifiers
#include <stdio.h>
int main() {
signed int s = -5;
unsigned int u = 5;
printf("%d %u", s, u);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
long long for Very Large Numbers
long long, introduced in C99, guarantees at least 64 bits of storage, making it the standard choice when a value might exceed what int or long can reliably hold across different systems.
Example: long long for Very Large Numbers
#include <stdio.h>
int main() {
long long big = 9000000000LL;
printf("%lld", big);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Choosing the Right Extended Type
Choosing the right extended type means balancing memory usage against the range of values actually needed: a small always-positive count fits in unsigned char, while a value that could exceed a billion needs long long.
Example: Choosing the Right Extended Type
#include <stdio.h>
int main() {
unsigned char smallCount = 200;
long long largeValue = 5000000000LL;
printf("%u %lld", smallCount, largeValue);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 21 topics to unlock
0/21 topics done
Complete these topics first:
- C Introduction
- C History & Features
- C Environment Setup
- C First Program
- C Syntax & Structure
- C Statements
- C Comments
- C Keywords & Identifiers
- C Data Types
- C Character Data Type
- C Numeric Data Types
- C Decimal (Floating-Point) Numbers
- C sizeof Operator
- C Extended Data Types
- C Type Conversion
- C Booleans
- C Variables
- C Changing Variable Values
- C Multiple Variables
- C Constants
- C Fixed-Width Integers