C 语言常用运算符
来源:互联网 发布:淘宝店排名规则 编辑:程序博客网 时间:2024/06/06 00:46
1.数学运算符
#include <iostream>#include <math.h>#define M_PI 3.14159265int main() { int32_t a = (10 + 2 - 8) * 9 / 3; printf("%d\n", a); printf("%f\n",sin(M_PI)); return 0;}
#include <stdint.h>#include <stdio.h>// && 与 ||或 !非#define MALE 1#define FEMALE 2int main() { int32_t score = 80; if (score >= 60 && score <= 100) { printf("OK\n"); } else { printf("Fail or invalid score\n"); } if (score < 60 || score > 100) { printf("Fail or invalid score\n"); } else { printf("OK\n"); } int sex = MALE; if (sex != FEMALE) { printf("The person is male\n"); } else { printf("The person is female\n"); } return 0;}
#include <stdio.h>#include <stdint-gcc.h>/** * & 位与 * | 位或 * ~ 位反 * ^ 异或 * >> 右移 * << 左移 */int main() { int a = 0b01; int b = 0b10; printf("位与:%d\n", a & b); printf("位或:%d\n", a | b); printf("异或:%d\n", a ^ b); uint8_t c = 1;//0b00000001 求反 0b11111110 printf("%d\n", c); c = ~c; printf("位反:%d\n", c); uint8_t d = 0b11111110; printf("%d\n", d); int8_t e = 1;//-128...-3,-2,-1, 中心 0,1,2.....-127 e = ~e; printf("位反:%d\n", e); int f = 8; printf("右移:%d\n", f >> 1); //提取颜色通道 uint32_t color = 0xFFFEFAFB;//ARGB(Alpha,Red,Green,Blue) uint32_t tmp = color & 0x00FF0000;//0b11111110 & 0b11111111 = 0b11111110 // tmp 0x00000000 11111110 00000000 00000000 uint8_t red = tmp >> 16; printf("%d\n",red); return 0;}
0 0
- C 语言常用运算符
- 3.C语言常用运算符
- C语言常用运算符优先级
- 黑马程序员----C语言:c中的一些常用运算符
- C语言运算符运算
- C语言编程入门——常用运算符
- C语言笔记系列(四)--运算符和常用语法
- 【C语言简单说】五:常用运算符
- C语言常用运算符与函数汇总
- C语言运算符
- C语言运算符
- C语言运算符
- C语言运算符
- C语言运算符
- C语言运算符
- C语言运算符
- C语言“++”运算符
- C语言运算符
- Leetcode Reverse Linked List
- 文章标题
- 银行日志处理
- 账户体系
- js map()
- C 语言常用运算符
- C语言输入与输出
- [01]Maven的学习笔记
- Leetcode 1. Two Sum
- 模3问题
- C语言数组
- Leetcode Reverse Bits
- 欢迎使用CSDN-markdown编辑器
- 使用 MEAN 进行全栈开发基础篇——5、接着前面玩儿编辑