C++ sizeof Operator Program Example

In this C++ programming practical tutorial we will see sizeof Operator Program Example in C++. sizeof operator is used to get the size in bytes of different datatypes in C++ e.g. int, double, float etc.

sizeof Operator Program Example in C++
#include <iostream>
using namespace std;

int main() {
    cout << "Size of char: " << sizeof(char) << " byte" << endl;
    cout << "Size of int: " << sizeof(int) << " bytes" << endl;
    cout << "Size of float: " << sizeof(float) << " bytes" << endl;
    cout << "Size of double: " << sizeof(double) << " bytes" << endl;
	return 0;
}
Output
Size of char: 1
Size of int: 4
Size of float: 4
Size of double: 8

Leave a Reply

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