ifの使い方
Posted: 2013年6月28日(金) 00:07
if(A==0)&&(B==0)||(C==0)||(D==0)
とした場合処理はどのよようになるのでしょうか。
とした場合処理はどのよようになるのでしょうか。
#include <stdio.h>
void test(void) {
int A=1,B=2,C=3,D=4;
if((A==0)&&(B==0)||(C==0)||(D==0))puts("test");
}
.file "if_dousa.c"
.section .rdata,"dr"
LC0:
.ascii "test\0"
.text
.globl _test
.def _test; .scl 2; .type 32; .endef
_test:
LFB6:
.cfi_startproc
pushl %ebp
.cfi_def_cfa_offset 8
.cfi_offset 5, -8
movl %esp, %ebp
.cfi_def_cfa_register 5
subl $40, %esp
movl $1, -12(%ebp)
movl $2, -16(%ebp)
movl $3, -20(%ebp)
movl $4, -24(%ebp)
cmpl $0, -12(%ebp)
jne L2
cmpl $0, -16(%ebp)
je L3
L2:
cmpl $0, -20(%ebp)
je L3
cmpl $0, -24(%ebp)
jne L1
L3:
movl $LC0, (%esp)
call _puts
L1:
leave
.cfi_restore 5
.cfi_def_cfa 4, 4
ret
.cfi_endproc
LFE6:
.def _puts; .scl 2; .type 32; .endef
#include <stdio.h>
void main(){
for( int A=0; A<2;A++ )
for( int B=0; B<2;B++ )
for( int C=0; C<2;C++ )
for( int D=0; D<2;D++ )
if((A==0)&& (B==0)|| (C==0)|| (D==0))
printf("○%d,%d,%d,%d\n",A,B,C,D);
else
printf("×%d,%d,%d,%d\n",A,B,C,D);
}
○0,0,0,0
○0,0,0,1
○0,0,1,0
○0,0,1,1
○0,1,0,0
○0,1,0,1
○0,1,1,0
×0,1,1,1
○1,0,0,0
○1,0,0,1
○1,0,1,0
×1,0,1,1
○1,1,0,0
○1,1,0,1
○1,1,1,0
×1,1,1,1
本当ですか?Loki さんが書きました: &&の方が優先順位が高いので、先に評価されます。
エラーになるんじゃないかな?usoire さんが書きました:if(A==0)&&(B==0)||(C==0)||(D==0)
とした場合処理はどのよようになるのでしょうか。
そうでした!これが正解でした!!non さんが書きました:エラーになるんじゃないかな?usoire さんが書きました:if(A==0)&&(B==0)||(C==0)||(D==0)
とした場合処理はどのよようになるのでしょうか。