C Data Types
In this page:
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
#include <stdio.h>
int main() {
int count = 100;
printf("%d, size: %zu bytes", count, sizeof(count));
return 0;
}
Login to try C/C++/Java/PHP code in the editor
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
#include <stdio.h>
int main() {
char grade = 'A';
printf("%c is ASCII %d", grade, grade);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
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
#include <stdio.h>
int main() {
float price = 19.99f;
printf("%.2f", price);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
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
#include <stdio.h>
int main() {
double pi = 3.14159265358979;
printf("%.10f", pi);
return 0;
}
Login to try C/C++/Java/PHP code in the editor
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
#include <stdio.h>
void greet() {
printf("Hello from a void function");
}
int main() {
greet();
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