#include<stdio.h>
#include<conio.h>
int main()
{
short t=1;
long k=54111;
unsigned u=10;
signed j=-10;
printf("t=%d",t);
printf("\nk=%d",k);
printf("\nu=%u",u);
printf("\nj=%d",j);
getch();
}
This program demonstrates the use of type modifiers in C programming. The program declares four variables: “t”, “k”, “u”, and “j” with the data types short, long, unsigned, and signed respectively.
The short data type is used to store small integer values and uses less memory compared to the int data type. It is usually represented by 2 bytes of memory. In the program, the variable “t” is declared as short and initialized with the value 1.
The long data type is used to store large integer values and uses more memory compared to the int data type. It is usually represented by 4 bytes of memory. In the program, the variable “k” is declared as long and initialized with the value 54111.
The unsigned data type is used to store non-negative integer values. It only stores positive integers and does not store any negative values. In the program, the variable “u” is declared as unsigned and initialized with the value 10.
The signed data type is used to store both positive and negative integer values. By default, all integers are considered signed integers. However, the signed keyword can be used to explicitly specify that the variable is a signed integer. In the program, the variable “j” is declared as signed and initialized with the value -10.
The printf() function is used to display the values of the variables. The format specifiers %d, %u are used to print the values of short, long, unsigned and signed variables respectively. The program output will be: t=1 k=54111 u=10 j=-10
It is important to note that short, long, unsigned, and signed are type modifiers and can be used with other data types such as int, char, etc.
Thanks