網站首頁 編程語言 正文
前言
運算符的作用:用于執(zhí)行代碼的運算
主要有:
1 算術運算符
用于處理四則運算
對于前置遞增:將遞增運算前置,使變量先加一,再進行表達式運算。
對于后置遞增:將遞增運算后置,使變量先進行表達式運算,再加一。
#include<iostream> using namespace std; int main() { //1.前置遞增:先加一,再進行表達式運算 int a = 10; int b = ++a * 10; cout << "a = " << a << endl; cout << "b = " << b << endl; //2.后置遞增:先進行表達式運算,再加一 int c = 10; int d = c++ * 10; cout << "c = " << c << endl; cout << "d = " << d << endl; system("pause"); return 0; }
2 賦值運算符
#include<iostream> using namespace std; int main1() { //賦值運算符 int a = 10; int b = 2; cout << "a = " << a << endl; //+= a = 10; a += b; cout << "a = " << a << endl; //-= a = 10; a -= b; cout << "a = " << a << endl; //*= a = 10; a *= b; cout << "a = " << a << endl; // /= a = 10; a /= b; cout << "a = " << a << endl; // %= a = 10; a %= b; cout << "a = " << a << endl; system("pause"); return 0; }
3 比較運算符
#include<iostream> using namespace std; int main() { cout << (4 == 3) << endl; cout << (4 != 3) << endl; cout << (4 < 3) << endl; cout << (4 > 3) << endl; cout << (4 >= 3) << endl; cout << (4 <= 3) << endl; system("pause"); return 0; }
4 邏輯運算符
#include<iostream>using namespace std;int main(){int a = 5;// 邏輯運算符 非cout << !a << endl;cout << !!a << endl;// 邏輯運算符 與int b = 0;int c = 3;cout << (a && b) << endl;cout << (a && c) << endl;//邏輯運算符 或cout << (!a || b) << endl;cout << (a || c) << endl;system("pause");return 0;}#include<iostream> using namespace std; int main() { int a = 5; // 邏輯運算符 非 cout << !a << endl; cout << !!a << endl; // 邏輯運算符 與 int b = 0; int c = 3; cout << (a && b) << endl; cout << (a && c) << endl; //邏輯運算符 或 cout << (!a || b) << endl; cout << (a || c) << endl; system("pause"); return 0; }
總結
原文鏈接:https://blog.csdn.net/qq_49030008/article/details/122825808
相關推薦
- 2022-10-28 Go保證并發(fā)安全底層實現(xiàn)詳解_Golang
- 2022-10-28 Templates實戰(zhàn)之更優(yōu)雅實現(xiàn)自定義View構造方法詳解_Android
- 2022-08-27 .Net實現(xiàn)延遲隊列_實用技巧
- 2022-05-31 Python學習之加密模塊使用詳解_python
- 2022-09-18 go?mock?server的簡易實現(xiàn)示例_Golang
- 2022-08-05 利用Python?list列表修改元素_python
- 2022-04-08 python實現(xiàn)有效的括號判斷實例代碼_python
- 2022-07-26 淺談Redis的事件驅動模型_Redis
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支