[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
在做C++的题目时,变量是必不可少的,今天我就来统计一下常用的几种定义类型。
1.int
int是大家写代码时90%的几率都会用到,作用是定义一个整数和整数数组。
举例:(写法:int 变量,……)
...... int s,a[10000009]; ......
2.long long
long long是定义一个比int更大的数,作用和int一样。
举例:(写法:long long 变量,……)
...... long long s,a[10000009]; ......
3.float
float的作用是定义一个小数和小数数组,不过范围较小。
举例:(写法:float 变量,……)
...... float s,a[10009]; ......
4.double
double是定义一个比float更大的小数,作用和float一样。
举例:(写法:double 变量,……)
...... double s,a[10000009]; ......
5.char
char是定义一个字符,注意只是一个,不过也能定义字符数组。
举例:(写法:char 变量,……)
...... char s,a[10000009]; ......
6.string
string是定义一条字符串,不限长度,照样能定义数组。
举例:(写法:string 变量,……)
...... string s,a[10000009]; ......
7.struct
struct是定义一个结构体,大括号中的变量可以那种都行。
举例:(写法:struct 变量,……)
...... struct jgt { int a; long long b; char c; float d; double e; string f;
}s[10000009]; ......
8.bool
bool是布尔值,可以分对错,也可以排序。
举例:(写法:……)
对错: bool s=true; /*或者*/ bool s=false; 排序: bool cmp(int x,int y) //变量名可以改 {
return x>y; }//大括号里的排序规则可以改变,用结构体排序也可以,这种排序常用于sort快排
9.void
void是一个自定义函数,可以在里面事先写好程序,在main函数里就可以更简便。
在做游戏的时候就经常用到。
举例:(写法:……)
写程序: void hs(int a) //变量随意 { ......; } 调颜色: void color(string c) {
if(c=="1")SetConsoleTextAttribute(......;
//变量随意,还用双引号中的部分,后面的怎么写看SetConsoleTextAttribute函数的用法 } main函数中用时:
1.void变量+(输入的其他变量); 2.void变量+(if中的==的后面); 如: hs(n); //n是一个输入的变量 color("1");
//"1"色
这些都是我用过的变量。