sizeof operator in C++

sizeof operator tells how much memory is used by the primitive data types. The C++ program uses sizeof operator to find the memory of primitive data types. The primitive data types are char, short, int, long, etc.

using namespace std;
int main(){
	cout<<"sizeof char: \t\t"<<sizeof(char)<<endl;
	cout<<"sizeof short : \t\t"<<sizeof(short)<<endl;
	cout<<"sizeof int : \t\t"<<sizeof(int)<<endl;
	cout<<"sizeof long : \t\t"<<sizeof(long)<<endl;
	cout<<"sizeof unsigned char: \t"<<sizeof(unsigned char)<<endl;
	cout<<"sizeof unsigned short : "<<sizeof(unsigned short)<<endl;
	cout<<"sizeof unsigned int : \t"<<sizeof(unsigned int)<<endl;
	cout<<"sizeof unsigned long : \t"<<sizeof(unsigned long)<<endl;
	cout<<"sizeof float: \t\t"<<sizeof(float)<<endl;
	cout<<"sizeof double : \t"<<sizeof(double)<<endl;
	cout<<"sizeof long double : \t"<<sizeof(long double)<<endl;
	return 0;
output of the above program, using sizeof perator
output of the above program, using sizeof perator

One Reply to “sizeof operator in C++”

Leave a Reply

Your email address will not be published. Required fields are marked *