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

C Data Types

Integer Type

int stores whole numbers with no fractional part, typically using 4 bytes of memory on modern systems, which gives it a range of roughly -2 billion to +2 billion -- more than enough for counters, indexes, and most everyday integer math.

Example: Integer Type

c
#include <stdio.h>
int main() {
	int count = 100;
	printf("%d, size: %zu bytes", count, sizeof(count));
	return 0;
}

Character Type

char stores a single character in exactly 1 byte, but internally it's really just a small integer representing that character's position in the ASCII table -- which is why you can do arithmetic directly on char values in C.

Example: Character Type

c
#include <stdio.h>
int main() {
	char grade = 'A';
	printf("%c is ASCII %d", grade, grade);
	return 0;
}

Floating-Point Type

float stores decimal numbers using 4 bytes and about 6-7 significant digits of precision, which is enough for many everyday calculations but can introduce small rounding errors in anything requiring exact decimal accuracy, like currency.

Example: Floating-Point Type

c
#include <stdio.h>
int main() {
	float price = 19.99f;
	printf("%.2f", price);
	return 0;
}

Double Type

double uses 8 bytes -- twice the space of float -- to store roughly 15-16 significant digits of precision, making it the default choice in C for decimal math where accuracy matters more than saving memory.

Example: Double Type

c
#include <stdio.h>
int main() {
	double pi = 3.14159265358979;
	printf("%.10f", pi);
	return 0;
}

Void Type

void represents the absence of a value and is most often used as a function's return type to signal that the function performs an action but doesn't hand any data back to its caller -- distinct from returning 0 or an empty string.

Example: Void Type

c
#include <stdio.h>
void greet() {
	printf("Hello from a void function");
}
int main() {
	greet();
	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.