Int Data Type in C
C-Int Data Type
On this page we will discuss about Int Data Type which is used in C. The Integer data type is used to store whole numbers which can be zero, positive, and negative values with no decimal.Int Data Type used in C
In C programming , the int data type can be both signed or unsigned. The unsigned int data type is used to store values in the range of zero to positive and signed int data type stores only negative values.If an integer variable is of unsigned type then it is assumed to be positive by default in C.
Declaration of Integer type variable
int variable;
The int data type in C can be further divided into short, int, and long data types.
The integer data types with their size and format specifier are given below in the table:
Type | Size (bytes) | Format Specifier |
---|---|---|
int | 4 bytes | %d |
unsigned int | 4 bytes | %u |
short int | 2 bytes | %hd |
unsigned short int | 2 bytes | %hu |
long int | 4 bytes | %ld |
unsigned long int | 4 bytes | %lu |
long long int | 8 bytes | %lld |
unsigned long long int | 8 bytes | %llu |
Note:
The storage size of integer data type is dependent on compiler as for 16 bit OS, size of int is 2 bytes and for 32 bit OS the size of int can be 2 bytes as well as 4 bytes.
Program to print Integer Data Types
Example 1:
Run
#include <stdio.h> int main() { // Integer value with positive data. int p = 13; // Integer value with negative data. int q = -13; // U or u is Used for Unsigned int in C. int r = 76U; // L or l is used for long int in C. long int s = 88889L; printf("The integer value with positive data is: %d\n", p); printf("The integer value with negative data is: %d\n", q); printf("The integer value with an unsigned int data is: %u\n", r); printf("The integer value with an long int data is: %ld", s); return 0; }
Output:
The integer value with positive data is: 13 The integer value with negative data is: -13 The integer value with an unsigned int data is: 76 The integer value with an long int data is: 88889
Example 2:
Run
#include <stdio.h> int main() { // Integer variable of type short. short int x=10000; // Integer variable of type int. int y=15612234; // Integer variable of type long. long number1=566678893324; // Integer variable of type long long. long long number2=81454486154787474; // Displaying the output on the screen printf("x is %hd \n y is %d \n number1 is %ld \n number2 is %lld \n",x,y,number1,number2); return 0; }
Output:
x is 10000 y is 15612234 number1 is 566678893324 number2 is 81454486154787474
Note:
If the result of an arithmetic operation is a decimal value,then an integer type variable will ignore the decimal point and will accept only the whole number. In case of short int, if the number is greater than 10000,then an incorrect value will be displayed for it.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment