c語言中“,?”的用法
這句語法看不懂,,誰能講講什么意思:(CutCount % 2 == 0) ? (SetCutDataFun(Num,1),EquRunFlag.CutBreakReadValtageFlag = 1) : (SetCutDataFun(0,1),EquRunFlag.CutBreakReadValtageFlag = 0);該行上下文是這樣的:}if(EnableCutFlag == 1){ if(EquRunFlag.CutTime200msFlag == 1) {EquRunFlag.CutTime200msFlag = 0;(CutCount % 2 == 0) ? (SetCutDataFun(Num,1),EquRunFlag.CutBreakReadValtageFlag = 1) : (SetCutDataFun(0,1),EquRunFlag.CutBreakReadValtageFlag = 0);if(CutCount++ >= CutNums){ CutCount = 0; SetCutDataFun(0,1); EquRunFlag.CutBreakReadValtageFlag =0; R595OEHigh(); ProPinHigh(); return 1; }}}
?在c語言中用于三目運(yùn)算符,,語法格式為:
邏輯表達(dá)式? 表達(dá)式1:表達(dá)式2
其實(shí)它很好理解 ,,就是條件判斷 if else 的另一種表示
相當(dāng)于
if (邏輯表達(dá)式) {表達(dá)式1 } else {表達(dá)式2}
你的
(CutCount % 2 == 0) ? (SetCutDataFun(Num,1),EquRunFlag.CutBreakReadValtageFlag = 1) : (SetCutDataFun(0,1),EquRunFlag.CutBreakReadValtageFlag = 0);
等價(jià)于:
if (CutCount % 2 == 0)
(SetCutDataFun(Num,1),EquRunFlag.CutBreakReadValtageFlag = 1);
else
(SetCutDataFun(0,1),EquRunFlag.CutBreakReadValtageFlag = 0);
Tags:語言