← Back to C Course | Chapter 1: Introduction & Basics | Lesson 14 of 21

C Extended Data Types

Extended data types combine a base type with modifiers -- short, long, signed, and unsigned -- that adjust its size, range, or ability to represent negative numbers.

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?

c
#include <stdio.h>
int main() {
	unsigned short small = 100;
	printf("%hu", small);
	return 0;
}

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

c
#include <stdio.h>
int main() {
	short s = 100;
	long l = 1000000L;
	printf("%hd %ld", s, l);
	return 0;
}

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

c
#include <stdio.h>
int main() {
	signed int s = -5;
	unsigned int u = 5;
	printf("%d %u", s, u);
	return 0;
}

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

c
#include <stdio.h>
int main() {
	long long big = 9000000000LL;
	printf("%lld", big);
	return 0;
}

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

c
#include <stdio.h>
int main() {
	unsigned char smallCount = 200;
	long long largeValue = 5000000000LL;
	printf("%u %lld", smallCount, largeValue);
	return 0;
}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.