整型
short num1 = 10;
int num2 = 10;
long num3 = 10;
long long num4 = 10;
cout<<"num1="<<num1<<endl;
cout<<"num2="<<num2<<endl;
cout<<"num3="<<num3<<endl;
cout<<"num4="<<num4<<endl;
cout<<"short类型占空间内存为:"<<sizeof(num1)<<endl;
cout<<"int类型占空间内存为:"<<sizeof(num2)<<endl;
cout<<"long类型占空间内存为:"<<sizeof(num3)<<endl;
cout<<"long long类型占空间内存为:"<<sizeof(num4)<<endl;
浮点型
float f1 = 3.1415926f;
double d1 = 3.1415926;
cout<< "f1=" << f1<<endl;
cout<< "d1=" << d1<<endl;
cout<<"float类型占空间内存为:"<<sizeof(f1)<<endl;
cout<<"double类型占空间内存为:"<<sizeof(d1)<<endl;
科学计数法
float f2 = 3e2;
float f3 = 3e-2;
cout<<"f2="<<f2<<endl;
cout<<"f3="<<f3<<endl;
字符型
char ch = 'a';
char ch2= 'b';
cout<<ch<<endl;
cout<<"char字符型变量所占内存:"<<sizeof(char)<<endl;
cout<< (int)ch <<endl;
cout<< (int)ch2 <<endl;
转义字符
cout<< "aaaaa\thelloworld"<<endl;
cout<< "aaa\thelloworld"<<endl;
cout<< "aaaaaaa\thelloworld"<<endl;
字符串
char str[] = "hello world";
cout<< str << endl;
string str2 = "hello world";
cout<<str2<<endl;
布尔类型
bool flag = true;
cout<<flag<<endl;
flag = false;
cout<<flag<<endl;
cout<<"size of bool = "<<sizeof(bool)<<endl;