C Program to find out the size and limits of data types
C Program: Size and Limits of Data Types
To find out the size and limits of data types in C, we can use the sizeof() operator and the limits.h header file. The sizeof() operator returns the size of a variable or data type in bytes. The limits.h header file defines macros for the minimum and maximum values of each data type.
C program prints the size and limits of all the built-in data types:
C program
#include
#include
int main() {
printf("Size of char: %zu bytes\n", sizeof(char));
printf("Minimum value of char: %d\n", CHAR_MIN);
printf("Maximum value of char: %d\n", CHAR_MAX);
printf("Size of short: %zu bytes\n", sizeof(short));
printf("Minimum value of short: %d\n", SHRT_MIN);
printf("Maximum value of short: %d\n", SHRT_MAX);
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Minimum value of int: %d\n", INT_MIN);
printf("Maximum value of int: %d\n", INT_MAX);
printf("Size of long: %zu bytes\n", sizeof(long));
printf("Minimum value of long: %ld\n", LONG_MIN);
printf("Maximum value of long: %ld\n", LONG_MAX);
printf("Size of long long: %zu bytes\n", sizeof(long long));
printf("Minimum value of long long: %lld\n", LLONG_MIN);
printf("Maximum value of long long: %lld\n", LLONG_MAX);
printf("Size of float: %zu bytes\n", sizeof(float));
printf("Minimum value of float: %e\n", FLT_MIN);
printf("Maximum value of float: %e\n", FLT_MAX);
printf("Size of double: %zu bytes\n", sizeof(double));
printf("Minimum value of double: %e\n", DBL_MIN);
printf("Maximum value of double: %e\n", DBL_MAX);
return 0;
}
Output:
Size of char: 1 bytes
Minimum value of char: -128
Maximum value of char: 127
Size of short: 2 bytes
Minimum value of short: -32768
Maximum value of short: 32767
Size of int: 4 bytes
Minimum value of int: -2147483648
Maximum value of int: 2147483647
Size of long: 8 bytes
Minimum value of long: -9223372036854775808
Maximum value of long: 9223372036854775807
Size of long long: 8 bytes
Minimum value of long long: -9223372036854775808
Maximum value of long long: 9223372036854775807
Size of float: 4 bytes
Minimum value of float: 1.175494350822287508e-38
Maximum value of float: 3.402823466e+38
Size of double: 8 bytes
Minimum value of double: 2.2250738585072014e-308
Maximum value of double: 1.7976931348623157e+308
Top Resources
Further Reading:
Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!