Este programa declara 4 variables de tipo int, float, double y char. Luego, el tamaño de cada variable se evalúa usando el operador sizeof.
Para encontrar el tamaño de la variable, sizeof
se utiliza el operador.
sizeof (tipo de datos);
Ejemplo: encontrar el tamaño de una variable
#include 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; )
Salida
Tamaño de char: 1 byte Tamaño de int: 4 bytes Tamaño de flotante: 4 bytes Tamaño de doble: 8 bytes
Nota: Puede obtener un resultado diferente si está utilizando una computadora vieja.