0
0
CConceptBeginner · 3 min read

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.

c
#include <stdio.h>

int main() {
    int age = 25;  // Store whole number 25
    printf("Age is %d\n", age);
    return 0;
}
Output
Age is 25
🎯

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

  • int stores 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.
It typically uses 4 bytes of memory and can hold positive and negative values.
Use int for counting, indexing, and integer math without decimals.
Declaring an int reserves space to store a whole number.
Printing an int uses the %d format specifier in printf.