当前位置:网站首页>[Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
[Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
2022-07-31 00:23:00 【HUAWEI CLOUD】
一、逻辑运算符
用于连接多个条件,一般来讲就是关系表达式,最终的结果也是一个 bool 值.
1.逻辑运算符的概念
| 运算符 | 说明 | 示例 |
|---|---|---|
| && | 逻辑 AND 运算符.如果两边的操作数都是 True,则条件 True,否则为 False | (A && B) 为 False |
| II | 逻辑 OR 运算符.如果两边的操作数有一个 True,则条件 True,否则为 False | (A II B) 为 True |
| ! | 逻辑 NOT 运算符.如果条件为 True,则逻辑 NOT 条件 False,否则为 True | !(A && B) 为 True |
相关案例:
package mainimport "fmt"func main() { var a bool = true var b bool = false if a && b { fmt.Printf("第一行 - 条件为 true \n") } if a || b { fmt.Printf("第二行 - 条件为 true \n") } // 修改 a 和 b 的值 a = false b = true if a && b { fmt.Printf("第三行 - 条件为 true \n") } else { fmt.Printf("第三行 - 条件为 false \n") } if !(a && b) { fmt.Printf("第四行 - 条件为 true \n") }}
二、其他运算符
1.位运算符的概念
| 运算符 | 说明 | 示例 |
|---|---|---|
| & | 如果两个操作数中都存在二进制AND运算符,则将其复制到结果. | (A&B)结果为12,也就是0000 1100 |
| I | 二进制OR运算符复制一个位,如果它存在于任一操作数. | (AIB)结果为61,也就是0011 1101 ^ 二进制XOR运算符复制位,如果它在一个操作数中设置,但不是在两个操作数中设置. (A^B)结果为49,也就是0011 0001 |
| << | 二进制左移位运算符.左操作数值向左移动由右操作数指定的位数. | A<<2结果为240,也就是1111 0000 |
| >> | 二进制右移运算符.左操作数值向右移动由右操作数指定位数. | A>>2结果为15,也就是0000 1111 |
2.地址相关运算符的概念
| 运算符 | 说明 | 示例 |
|---|---|---|
| & | 返回变量的地址 | &a将给出变量a的实际地址. |
* | 指向变量的指针 | *a是指向变量a的指针. |
边栏推荐
- 【愚公系列】2022年07月 Go教学课程 013-常量、指针
- VSCode高效开源神器有哪些
- MySQL数据库的truncate与delete区别
- 46.
- Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
- C language force buckles the rotating image of the 48th question.auxiliary array
- ABC 261 F - Sorting Color Balls(逆序对)
- software development design process
- MySQL系列一:账号管理与引擎
- MySQL笔记下
猜你喜欢

The difference between h264 and h265 decoding

xss靶机训练【实现弹窗即成功】

Homework: iptables prevent nmap scan and binlog

h264和h265解码上的区别

论文理解:“Designing and training of a dual CNN for image denoising“

mysql主从复制及读写分离脚本-亲测可用

How to Repair Word File Corruption

在微服务中使用事件溯源的六大原因 - Herath

MySQL table design for message queue to store message data

pytorch双线性插值
随机推荐
VSCode高效开源神器有哪些
joiplay模拟器rtp如何安装
xss绕过:prompt(1)
Axure Carousel
pytorch bilinear interpolation
Error ER_NOT_SUPPORTED_AUTH_MODE Client does not support authentication protocol requested by serv
Error occurred while trying to proxy request项目突然起不来了
WMware Tools安装失败segmentation fault解决方法
[In-depth and easy-to-follow FPGA learning 14----------Test case design 2]
WEB安全基础 - - -漏洞扫描器
XSS相关知识
MySQL grant statements
encrypted transmission process
.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
软件开发设计流程
How to adjust Chinese in joiplay simulator
正则表达式密码策略与正则回溯机制绕过
Linux 部署mysql 5.7全程跟踪 完整步骤 django部署
SereTOD2022 Track2 Code Analysis - Task-based Dialogue Systems Challenge for Semi-Supervised and Reinforcement Learning
what is jira