Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
int a = 8; if (a==8) printf("x"); else printf("y");
と等しいaのに8を出力しますy。
a
8
y
上記のコードは常にx. コードが何か他のものを出力する場合、質問で重要な情報を省略しています。
x
それが何であるかを調べるには、これを試してください:
#undef aの前に挿入int a = 8;して、コードを台無しにする C プリプロセッサ マクロがないことを確認します。
#undef a
int a = 8;
条件を入れ替えて、a本当に期待どおりかどうかを確認します。
if( 8 == a )
if( a = 8 )この小さなトリックにより、偶発的な割り当てバグ ( )も防止できます。
if( a = 8 )