How to find the size of the data types in C++

1 Answer

0 votes
#include <iostream>

int main()
{
	using namespace std;

	cout << "Size of char = " << sizeof(char) << " byte" << endl;
	cout << "Size of bool = : " << sizeof(bool) << " bytes" << endl;
	cout << "Size of int = : " << sizeof(int) << " bytes" << endl;
	cout << "Size of long = : " << sizeof(long) << " bytes" << endl;
	cout << "Size of long long = : " << sizeof(long long) << " bytes" << endl;
	cout << "Size of float = " << sizeof(float) << " bytes" << endl;
	cout << "Size of double = " << sizeof(double) << " bytes" << endl;
	cout << "Size of long double = " << sizeof(long double) << " bytes" << endl;

	return 0;
}



/*
run:

Size of char = 1 byte
Size of bool = : 1 bytes
Size of int = : 4 bytes
Size of long = : 4 bytes
Size of long long = : 8 bytes
Size of float = 4 bytes
Size of double = 8 bytes
Size of long double = 8 bytes

*/

 



answered Jun 6, 2017 by avibootz

Related questions

1 answer 302 views
1 answer 193 views
193 views asked Jan 18, 2017 by avibootz
1 answer 134 views
1 answer 186 views
1 answer 230 views
1 answer 226 views
...