Lesson not found
Lesson Progress: 0%
Integer types store whole numbers — numbers without a decimal point. C provides several integer types that use different amounts of memory and can hold different ranges of values. The most common is int, but there is also short for smaller values, long for larger values, and unsigned int for non-negative numbers. Choosing the right integer type helps your program use memory efficiently and avoid errors when values go out of range. Understanding integer types is a key step toward writing professional C code that runs well on any system.
#include <stdio.h>
int main() {
int a = 100;
printf("%d\n", a);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int is the standard integer type and can hold whole numbers like 100, -5, or 0.int as the default choice for counting, indexing, and simple math.int uses 4 bytes of memory and can store values from about -2 billion to +2 billion.%d format specifier prints an int value.int a = 100; creates a variable named a holding the value 100.#include <stdio.h>
int main() {
short b = 25;
printf("%d\n", b);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
short is a smaller integer type that uses less memory than int.short typically uses 2 bytes and holds values from about -32,000 to +32,000.short when you know your numbers will stay small and you want to save memory.short, you can still print it with %d because short values are automatically promoted to int when passed to printf.short b = 25; works just like int, but the variable can only hold a smaller range of numbers.#include <stdio.h>
int main() {
long c = 50000;
printf("%ld\n", c);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
long is a larger integer type that can hold bigger values than int.long uses 8 bytes and can store values up to about 9 quintillion.long is %ld (long decimal).long when you need to work with very large whole numbers that would not fit in an ordinary int.long c = 50000; creates a long variable, even though 50000 would also fit in an int.#include <stdio.h>
int main() {
unsigned int d = 300;
printf("%u\n", d);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
unsigned int can only hold non-negative numbers (zero or positive).unsigned int can hold twice as many positive numbers as a regular int.unsigned int is %u (unsigned decimal).unsigned for values that should never be negative, like counts, ages, or sizes.unsigned int d = 300; declares an unsigned variable and stores 300 in it.#include <stdio.h>
int main() {
int x = 7;
int y = 2;
printf("%d\n", x / y);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
7 / 2 equals 3 in integer math, not 3.5, because both values are int.double, the division happens first using integer rules.double or float.#include <stdio.h>
int main() {
int z = -15;
printf("%d\n", z);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
int z = -15; stores the negative number -15 in the variable z.%d format specifier handles negative numbers automatically and prints the minus sign.signed is the default for int, short, and long, meaning they can hold both positive and negative values.unsigned types forbid negative values, which doubles the positive range.Test Incomplete