C语言运算符指南:从小白到精通,掌握算术、关系和逻辑运算符

2023-06-29 0 932

当谈及C词汇的操作符时,微积分操作符、亲密关系操作符和方法论操作符是最常用的四类。它在程式设计中承担着关键的配角,让他们逐一展开详尽的传授。

微积分操作符:

加法操作符(+):用作将三个数组相加。减法操作符(-):用作从第二个数组中乘以第三个数组。加法操作符(*):用作将三个数组相加。加法操作符(/):用作将第二个数组乘以第三个数组。取余操作符(%):回到三个数组相加的平方根。

亲密关系操作符:

成正比操作符(==):检查和三个数组与否成正比,假如成正比则回到1,不然回到0。左右操作符(!=):检查和三个数组与否不成正比,假如不成正比则回到1,不然回到0。小于操作符(>):检查和第二个数组与否小于第三个数组,假如是则回到1,不然回到0。小于操作符(<):检查和第二个数组与否小于第三个数组,假如是则回到1,不然回到0。小于等同于操作符(>=):检查和第二个数组与否小于等同于第三个数组,假如是则回到1,不然回到0。小于等同于操作符(<=):检查和第二个数组与否小于等同于第三个数组,假如是则回到1,不然回到0。

方法论操作符:

方法论与操作符(&&):假如三个数组都为真,则回到真,不然回到假。方法论或操作符(||):假如三个数组中最少有两个为真,则回到真,不然回到假。方法论非操作符(!):用作探底回升数组的方法论状况。假如前提为真,则方法论非操作符将回到假,假如前提为假,则回到真。

那些操作符在C词汇中十分常用,因此在展开数值排序、前提推论和方法论运算时时常加进。为的是更快地认知它的用语,他们上看许多实例:

实例 1:微积分操作符

#include <stdio.h> int main() { int a = 10, b = 3; intsum = a + b;int difference = a – b; int product = a * b; int quotient = a / b; int remainder = a % b; printf(“Sum: %d\n”, sum); printf(“Difference: %d\n”, difference); printf(“Product: %d\n”, product); printf(“Quotient: %d\n”, quotient); printf(“Remainder: %d\n”, remainder); return 0; }

输出:

Sum: 13 Difference: 7 Product: 30 Quotient: 3 Remainder: 1

实例 2:亲密关系操作符

#include <stdio.h> int main() { int a = 5, b = 3; if (a == b) { printf(“a is equal to b\n”); } else { printf(“a is not equal to b\n”); } if (a > b) { printf(“a is greater than b\n”); } else { printf(“a is not greater than b\n”); } if (a < b) { printf(“a is less than b\n”); } else { printf(“a is not less than b\n”); } return 0; }

输出:

a is not equal to b a isgreater than b ais not less than b

实例 3:方法论操作符

#include <stdio.h> int main() { int a = 5, b = 3; if (a > 0 && b > 0) { printf(“Both a and b are positive\n”); } if (a > 0 || b > 0) { printf(“At least one of a and b is positive\n”); } if (!(a > 0)) { printf(“a is not positive\n”); } return 0; }

输出:

Both a and b are positive At least one of a and b is positive a is not positive

通过以上实例,你可以更快地认知和使用C词汇中的常用操作符。当然,除了那些操作符,C词汇还有其他类型的操作符,如位操作符、赋值操作符等。

每天坚持学习一点点,不求有回报,只愿可以丰富自己!!!

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务