In this Program, you’ll learn how to find size of operator.
Here declares 4 variables of type int, float, double and char. Then, the size of each variable is evaluated using size of operator.
To nicely understand this example to find size of operator, you should have the knowledge of following C++ programming topics:
- C++ I/O
To find the size of the variable, size of
operators is used.
sizeof(dataType);
Program to Find Size of a Variable
#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 byte Size of int: 4 bytes Size of float: 4 bytes Size of double: 8 bytes
Note: You may get a different result if you are using an old computer.
Related Programs
- C++ “Hello, World!” Program
- C++ Program to Print Number Entered by User
- C++ Program to Add Two Numbers
- C++ Program to Find Quotient and Remainder
- C++ Program to Swap Two Numbers
- C++ Program to Find ASCII Value of a Character
- C++ Program to Multiply two Numbers
Ask your questions and clarify your/others doubts on C++ Program to Find Size of operators by commenting. Documentation.
Please write to us at [email protected] to report any issue with the above content or for feedback.