Keyword long is used for altering the size of data type. For example: the size of
Thus,
Similarly, the long keyword can be used double and floats types.
int
is either 2 bytes or 4 bytes but, when long keyword is used, the size of long int
will be either 4 bytes or 8 bytes. Also, you can use long long int
. The size of long long int
is generally 8 bytes. This program will demonstrate the size of keyword long for my system. It may be different in your system.Source Code
#include <stdio.h>
int main(){
int a;
long int b; /* int is optional. */
long long int c; /* int is optional. */
printf("Size of int = %d bytes\n",sizeof(a));
printf("Size of long int = %ld bytes\n",sizeof(b));
printf("Size of long long int = %ld bytes",sizeof(c));
return 0;
}
Output
Size of int = 4 bytesIn this program, the sizeof operator is used for finding the size of
Size of long int = 4 bytes
Size of long long int = 8 bytes
int
, long int
and long long int
.Thus,
int
and long int
for my system can hold values from -231 to 231-1. If I have to work on data outside this range, I have to use long long int
, which can hold values from -263 to 263-1 .Similarly, the long keyword can be used double and floats types.
Post a Comment