1 /*test sizeof () test environment: Windows 7 64-bit operating system VS2012 compiler*/2#include <iostream>3 using namespacestd;4 5 intMain ()6 {7 CharA;8 Short intb;9 intC;Ten Long intD; One floate; A DoubleF; - Long DoubleG; - int*h; the Double*i; - float*J; - stringstrArr1; - +cout <<"sizeof (char) ="<<sizeof(a) <<Endl; -cout <<"sizeof (short int) ="<<sizeof(b) <<Endl; +cout <<"sizeof (int) ="<<sizeof(c) <<Endl; Acout <<"sizeof (long int) ="<<sizeof(d) <<Endl; atcout <<"sizeof (float) ="<<sizeof(e) <<Endl; -cout <<"sizeof (double) ="<<sizeof(f) <<Endl; -cout <<"sizeof (long double) ="<<sizeof(g) <<Endl; -cout <<"sizeof (int*) ="<<sizeof(h) <<Endl; -cout <<"sizeof (double*) ="<<sizeof(i) <<Endl; -cout <<"sizeof (float*) ="<<sizeof(j) <<Endl; incout <<"sizeof (string) ="<<sizeof(STRARR1) <<Endl; - toSystem"Pause"); + - return 0; the}
Test results:
Usage of sizeof in C + +