#include <cstdlib>
#include <iostream>
using namespace std ;
int main( int nNumberofArgs , char* pszArgs[ ] )
{
bool b ;
char c ;
int n ;
long l ;
float f ;
double d ;
cout << "sizeof a bool = " << sizeof b << endl ;
cout << "sizeof a char = " << sizeof c << endl ;
cout << "sizeof an int = " << sizeof n << endl ;
_________________
105 стр. Глава 8. Первое знакомство с указателями в С++
cout << "sizeof a long = " << sizeof l << endl ;
cout << "sizeof a float = " << sizeof f << endl ;
cout << "sizeof a double= " << sizeof d << endl ;
/* Пауза для того, чтобы посмотреть на результат работы программы */
system( "PAUSE" ) ; return 0 ;
}
Оператор sizeof представляет собой специальную инструкцию С++, которая возвращает размер своего аргумента в байтах. Вот как выглядит вывод данной программы, скомпилированной Dev-C++:
sizeof a bool = 1
sizeof a char = 1
sizeof an int = 4
sizeof a long = 4
sizeof a float = 4
sizeof a double= 8