The sizeof() operator in C++ returns the size of a data type or variable in bytes. Here are some examples of its output for different data types:
std::cout << "Integer Types Memory Size:" << std::endl;
std::cout << "short: " << sizeof(short) << " bytes" << std::endl; // Typically 2 bytes
std::cout << "int: " << sizeof(int) << " bytes" << std::endl; // Typically 4 bytes
std::cout << "long: " << sizeof(long) << " bytes" << std::endl; // Typically 8 bytes
std::cout << "long long: " << sizeof(long long) << " bytes" << std::endl; // Typically 8 bytes
std::cout << "\nFloating-Point Types Memory Size:" << std::endl;
std::cout << "float: " << sizeof(float) << " bytes" << std::endl; // Typically 4 bytes
std::cout << "double: " << sizeof(double) << " bytes" << std::endl; // Typically 8 bytes
std::cout << "long double: " << sizeof(long double) << " bytes" << std::endl; // Typically 16 bytes
std::cout << "\nOther Types Memory Size:" << std::endl;
std::cout << "char: " << sizeof(char) << " bytes" << std::endl; // 1 byte
std::cout << "bool: " << sizeof(bool) << " bytes" << std::endl; // 1 byte
The actual sizes may vary depending on the system architecture and compiler.
