Write a program with several variables of various data types such as int, long long int, float, double, char, and check their sizes in terms of bytes.
Make sure you do screen output of the bytes.
For C++ please
#include <iostream>
using namespace std;
int main()
{
int integerType;
long long int longlongType;
float floatType;
double doubleType;
char charType;
// int
cout << "Size of int is: " << sizeof(integerType) << " bytes\n";
// long long int
cout << "Size of long long int is: " << sizeof(longlongType) << " bytes\n";
// float
cout << "Size of float is: " << sizeof(floatType) << " bytes\n";
// double
cout << "Size of double is: " << sizeof(doubleType) << " bytes\n";
// char
cout << "Size of char is: " << sizeof(charType) << " bytes\n";
return 0;
}
OUTPUT:
Explanation: We can use sizeof() function to calculate the size of different data types in C++.
Get Answers For Free
Most questions answered within 1 hours.