網站首頁 編程語言 正文
前言
運算符的作用:用于執行代碼的運算
主要有:
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
相關推薦
- 2024-03-24 feignClient注入失敗
- 2022-10-17 C++實現String類的方法詳解_C 語言
- 2022-09-17 使用cache加快編譯速度的命令詳解_相關技巧
- 2023-01-03 c語言malloc函數的用法示例和意義_C 語言
- 2022-07-03 Go?的入口函數和包初始化的使用_Golang
- 2022-07-16 mac拷貝文件到Linux服務器、運行jar包,以及常用為Linux文件操作命令
- 2022-09-01 openGauss數據庫在CentOS上的安裝實踐記錄_數據庫其它
- 2023-03-26 WPF使用觸發器需要注意優先級問題解決_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支