1.电子称模拟
#include <iostrem>
using namespace std;
int main()
{
float apple_price = 3.0;
float apple_weight = 0;
float banana_price = 4.0;
float banana_weight = 0;
float total = 0;
cout<<"apple weight:"<<endl;
cin>>apple_weight;
cout<<"banana weight"<<endl;
cin>>banana_wegiht;
total = apple_price*apple_weight + banana_price*banana_weight;
cout<<"price "<<total<<endl;
return 0;
}
2.数据类型
- 整型:int整型(4个字节,-2^31~2^31-1),unsigned int无符号整型(0~2^32-1),long int(4个字节),unsigned long int无符号长整型
- 实型,实数类型:float(4个字节,-3.4*10^38~3.4*10^38),double float(8个字节,±1.7*10^308),long double(10个字节,-3.4*10^4932~1.1*10^4932)
- bool布尔型(1个字节,true&false)
- 字符型char(1个字节)
3.变量内存单元地址(&:取得变量内存单元地址)
- 内存单元地址,cout会自动以16进制形式输出地址值,开头两位字符固定为0x或0X
- 若变量类型为字符,则cout不是输出变量地址,而是输出变量内容,且将相邻的后续内存单元存储的字符内容也进行输出,直到碰到一个内容为0的内存单元
4. *n ,指的是变量n存储地址值所对应的内容
cout << n << *pn << endl;