Int Data Type


In C programming, the int data type is used to represent whole numbers. It allows you to store both positive and negative integers for various numerical operations and calculations.

tips_and_updates The int data type is commonly used in C for tasks such as counting, indexing, arithmetic calculations, and more. It provides a range of values that can be stored, determined by the number of bytes it occupies.

#include <stdio.h>
int main() {
int age = 25;
int quantity = -10;
int sum = age + quantity;
printf("Age: %d\n", age);
printf("Quantity: %d\n", quantity);
printf("Sum: %d\n", sum);

return 0;
}

In the above example, we declare three int variables: age, quantity, and sum.

The age variable stores the value 25, the quantity variable stores the value -10, and the sum variable stores the sum of age and quantity.

The printf statements are used to print the values of these variables using the %d format specifier.

The int data type is primarily used for whole numbers, but it also supports various arithmetic operations.


#include <stdio.h>
int main() {
int x = 10;
int y = 5;
int addition = x + y;
int subtraction = x - y;
int multiplication = x * y;
int division = x / y;
printf("Addition: %d\n", addition);
printf("Subtraction: %d\n", subtraction);
printf("Multiplication: %d\n", multiplication);
printf("Division: %d\n", division);

return 0;
}

In this example, we perform various arithmetic operations using int variables. The variables x and y store the values 10 and 5, respectively. The addition variable stores the result of x + y, the subtraction variable stores the result of x - y, the multiplication variable stores the result of x * y, and the division variable stores the result of x / y.

The int data type has a specific range of values it can store, depending on the number of bytes it occupies. By default, an int typically occupies 4 bytes and can represent values from approximately -2,147,483,648 to 2,147,483,647. If you need to work with larger numbers, you can use long int or long long int data types, which occupy more bytes and provide a wider range of values.

Loading...

Search