Chapter 2 – Q #9: Total Purchase – Tony Gaddis – Starting Out With C++
Problem: -
You have been given a job as a programmer on a Cyborg supercomputer. In order to accomplish some calculations, you need to know how many bytes the following data types use: char, int, float, and double. You do not have any manuals, so you can't look this information up. Write a C++ program that will determine the amount of memory used by these types and display the information on the screen.
Solution: -
#include <iostream>
#include<iomanip>
using namespace std;
int main()
{
cout << "Char Data Type
Size is " << sizeof(char) << " Bytes" << endl;
cout << "Int Data Type
Size is " << sizeof(int) << " Bytes" << endl;
cout << "Float Data Type
Size is " << sizeof(float) << " Bytes" << endl;
cout << "Double Data Type Size
is " << sizeof(double) << " Bytes" << endl;
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Explanation of this Solution
- You can check size of any data type by using sizeof keyword.
- I did only in this question, Display output on the screen by using sizeof keyword for data type size.
- only write in sizeof(data type)
- Return 0 to the main function.
Also, I attach CPP file of this problem. You can download this file
0 Comments