This program includes the climits
and cfloat
header files, which define constants for the minimum and maximum values of int
and float
, respectively. It also includes the cmath
header file, which defines constants for the minimum and maximum values of double
.
The sizeof
operator returns the size of a data type in bytes. The program uses it to print the size of int
, float
, double
, and char
in bytes. It also prints the minimum and maximum values of int
, float
, and double
using the constants defined in the climits
, cfloat
, and cmath
header files, respectively.
I hope this helps! Let me know if you have any questions.
#include <iostream>
#include <climits> // for INT_MAX and INT_MIN
#include <cfloat> // for FLT_MAX and FLT_MIN
#include <cmath> // for DBL_MAX and DBL_MIN
int main()
{
std::cout << "Size of int: " << sizeof(int) << " bytes" << std::endl;
std::cout << "Minimum value of int: " << INT_MIN << std::endl;
std::cout << "Maximum value of int: " << INT_MAX << std::endl;
std::cout << "Size of float: " << sizeof(float) << " bytes" << std::endl;
std::cout << "Minimum value of float: " << FLT_MIN << std::endl;
std::cout << "Maximum value of float: " << FLT_MAX << std::endl;
std::cout << "Size of double: " << sizeof(double) << " bytes" << std::endl;
std::cout << "Minimum value of double: " << DBL_MIN << std::endl;
std::cout << "Maximum value of double: " << DBL_MAX << std::endl;
std::cout << "Size of char: " << sizeof(char) << " bytes" << std::endl;
return 0;
}
Leave a Reply