[{"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}]
<>案例一:
#include "stdio.h" void main() { int x,y,z; x=1,y=1; z=x++,y++,++y; //逗号表达式
printf("%d,%d,%d\n",x,y,z); }
你觉得这个z值是多少呢?
分析:这个x++, y++, ++y 这是个逗号表达式,运算顺序自左至右,那有人要说了,简单,z = 2,
那我可要告诉你:错误;为啥错了?因为本例中z=x++含有赋值运算符,其优先级高于逗号逗号运算符,也即相当于这样 (z=x++),y++,++y;
运行结果:
解析:首先执行(z=x++) => z=1, x=2
然后继续执行y++, ++y => y=3
**此时若再次变化成这样:** z= (x++,y++,++y); //此时逗号表达式整体加了括号 printf("%d,%d,%d\n",x,y,z);
此时运行结果:
<>案例二:
void main() { int t; printf("t=%d\n",(t=1,t+5,t++)); }
自己分析一把,答案是1!
有人说,我认为是6,自左至右计算后的t是6!
是吗? => 错误;
原因:逗号表达式中的t+5并不会影响t的值啊!
经过t=1,t+5后t的值仍然是1,经历t++时,注意此时是先赋值,然后再自增,所以逗号表达式的值是1;
运行结果:
**
<>案例三:
**
void main(){ int a,b; b=(a=1,a+1,a++); printf("b= %d\n",b); }
和案例二差不多,自己分析一把,在评论区可写下自己的解题过程,答案是1。
<>最后总结一下:
1. 逗号表达式结构:
表达式1,表达式2,表达式3,… ,表达式n
2. 逗号表达式的要领:
(1) 逗号表达式的运算过程为:【从左往右】逐个计算表达式。
(2) 逗号表达式作为一个整体,【它的值】为最后一个表达式(也即表达式n)的值。
(3) 逗号运算符的优先级别在所有运算符中最低。
(4)往往将逗号表达式与赋值运算符结合起来考查!