LoginSignup
7
6

More than 5 years have passed since last update.

未初期化のBOOL値とif文の省略

Last updated at Posted at 2014-08-09

謎の現象に遭遇したのでどういう理屈か教えてください。

例えば

BOOL test;

if (test == YES) NSLog(@"1");
if (test) NSLog(@"2");


BOOL question;

if (question) NSLog(@"3");
if (question == YES) NSLog(@"4");

//おまけ
question = !question;

if (question) NSLog(@"5");
if (question == NO) NSLog(@"6");
if (question == YES) NSLog(@"7");

をXcodeで実行した時に

1
2
3
6

が出力されます。

なぜ、1 は出力され 4 は出力されないのでしょうか?
これは初期化してあるはずのものでも同様の事がおこりました。

if (test)

if (test == YES)
に違いがあるのでしょうか?

もしかしたら情報科学の方達には当たり前のことかも知れないですが、どなたか教えてください。
謎過ぎて眠れません。

7
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6