To find the size of variable, sizeof
operator is used.
his program declares 4 variables of type int, float, double and char. Then, the size of each variable is evaluated using sizeof operator.
1 2 3 4 5 6 7 8 9 10 11 12 | #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: