c中的and,not等邏輯運算符


c語言中本身的邏輯運算符為 ! != && 等
在C99規范中,引入iso646頭文件可以像python一樣使用 and not 作為邏輯符號
其原理很簡單,為宏定義的方式將and等詞定義為相關的邏輯運算符
需要注意的是
雖然宏定義方式為直接替換
但 !x 不能寫成 notx 的方式 必須加空格予以區分,不然編譯器會認為notx為一個變量而編譯不通過

iso646頭文件內容

include<iso646.h>

define and &&

define and_eq &=

define bitand &

define bitor |

define compl ~

define not !

define not_eq !=

define or ||

define or_eq |=

define xor ^

define xor_eq ^=


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM