代码里用指针交换两个数的时候,为什么分隔符可以用,和;?
这种操作有什么相关规定吗?该怎么称呼这种规则?
#include
int main()
{
int a,b;//extern int a,b;Error! Should be used in .h file
struct {
int a;
int b;
/* data */
} temp;
temp.a = a; temp.b = b; //这两行
a = temp.b; b = temp.a;//
printf(" 输入需要交换的两个数,用单个空格隔开");
scanf("%d %d",&(temp.a),&(temp.b));
printf(" 交换完了:%d %d\n 再见",temp.b,temp.a);
return 0;
}
逗号运算符:https://baike.baidu.com/item/%E9%80%97%E5%8F%B7%E8%BF%90%E7%AE%97%E7%AC%A6/7959271?fr=aladdin
三目运算符:https://baike.baidu.com/item/%E6%9D%A1%E4%BB%B6%E8%BF%90%E7%AE%97%E7%AC%A6/6180633?fr=aladdin
';' 分号的作用为两种:语句分隔符和语句终止符。
“,”表示并列,“;”表示一个语句结束