13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Objective-Cでやるとどうなるのか、何となく気になってやってみました。

やってみた1

- (void)hoge {

	NSLog("わります:%i",10000/0);

}


出力は 2012-11-29 01:02:01.692 hoge[17496:907] わります:2 でした、何これ怖い。

続きましてこちら。

やってみた2

- (void)hoge {

    int result = 10000/0;
    NSLog(@"わります:%i",result);

}


出力は 2012-11-29 01:09:36.248 hoge[17529:907] わります:6 さっきは2って言ったのに…。

最後にこちら。

やってみた3

- (void)hoge {

    NSLog(@"わります1:%i",100/0);
    NSLog(@"わります2:%i",10/0);
    NSLog(@"わります3:%i",1/0);

}

2012-11-29 01:13:31.333 hoge[17583:907] わります1:2
2012-11-29 01:13:31.335 hoge[17583:907] わります2:515551232
2012-11-29 01:13:31.336 hoge[17583:907] わります3:515551232
もうやだ。

結論
別にアプリケーションの強制終了とかはしないけど
#よい子もわるい子もゼロ除算をしてはいけません。

13
13
4

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
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?