C++ Tutorial/Language Basics/Variable size — различия между версиями
Admin (обсуждение | вклад) м (1 версия: Импорт контента...) |
|
(нет различий)
|
Текущая версия на 10:30, 25 мая 2010
Variable size: int, short, long, char, float and double
#include <iostream>
int main()
{
std::cout << "The size of an int is:\t\t";
std::cout << sizeof(int) << " bytes.\n";
std::cout << "The size of a short int is:\t";
std::cout << sizeof(short) << " bytes.\n";
std::cout << "The size of a long int is:\t";
std::cout << sizeof(long) << " bytes.\n";
std::cout << "The size of a char is:\t\t";
std::cout << sizeof(char) << " bytes.\n";
std::cout << "The size of a float is:\t\t";
std::cout << sizeof(float) << " bytes.\n";
std::cout << "The size of a double is:\t";
std::cout << sizeof(double) << " bytes.\n";
return 0;
}
The size of an int is: 4 bytes. The size of a short int is: 2 bytes. The size of a long int is: 4 bytes. The size of a char is: 1 bytes. The size of a float is: 4 bytes. The size of a double is: 8 bytes.