What is int in C: Explanation and Example
int in C is a data type used to store whole numbers without decimals. It typically holds values like -32768 to 32767 or larger depending on the system, and is one of the basic building blocks for storing numeric data in C programs.How It Works
Think of int as a labeled box that can hold whole numbers, like counting apples or people. It does not store fractions or decimals, only complete numbers.
Inside the computer, this box uses a fixed amount of space (usually 4 bytes on modern systems) to remember the number. Because the space is fixed, there is a limit to how big or small the number can be.
When you declare a variable as int, you tell the computer to reserve this box so you can store and work with whole numbers easily in your program.
Example
This example shows how to declare an int variable, assign a value, and print it.
#include <stdio.h> int main() { int age = 25; // Store whole number 25 printf("Age is %d\n", age); return 0; }
When to Use
Use int when you need to work with whole numbers like counts, indexes, or simple math without decimals. For example, counting items in a list, storing a person's age, or looping a fixed number of times.
It is the most common choice for integer numbers because it balances memory use and range well on most systems.
Key Points
intstores whole numbers without decimals.- It usually uses 4 bytes of memory on modern computers.
- It can hold both positive and negative numbers.
- Use it for counting, indexing, and simple integer math.
Key Takeaways
int is used to store whole numbers in C programs.int for counting, indexing, and integer math without decimals.int reserves space to store a whole number.int uses the %d format specifier in printf.