/* 浮点型,float 和double类型,float占4个字节,double占8个字节 查看数据类型或者变量占用的内存用关键字sizeof(); */ float speed = 100.3f; //float类型小数点后加f,因为小数默认为double类型,需要转化为float,省去了这步骤 double force = 12.5; cout << "速度是:" <<sizeof(speed) << endl; cout << "力是:" << sizeof(force) << endl; //科学计数法 float sce1 = 3e2f; cout << "sce1=" << sce1 << endl; //e2表示10^2 float sce2 = 4e-2f; cout << "sce2=" << sce2 << endl; //e-2表示10 /* 字符数据类型char,占一个字节,计算机在处理字符的时候,会将其先转化为ASCII码 然后再将对应的ASCII码转为0、1二进制串。 */ char ch = '3'; cout << "字符串占的内存是:" << sizeof(ch) << endl; /* 转义字符, ,\, :水平制表符 */ cout << "GoodGirl " << endl; cout << "GooGirl abc" << endl; cout << "BGirl abc" << endl; /* 字符串类型 C风格和C++风格 */ char str1[] = "good"; cout << str1 << endl; string str2 = "bad"; cout << str2 << endl; /* 布尔类型,占用一个字节的内存空间 */ bool success = true; cout << success << endl; /* 键盘输入:cin>> */ int num = 1; cout << "请输入一个整数:"<<endl; cin >> num; cout << num << endl;