初級 › Floating point exception(整数のゼロ除算) › パターン1
Floating point exception(整数のゼロ除算)
int型を0で割ったときに発生するクラッシュです。
1 #include <stdio.h> 2 3 int main(void) { 4 int total = 10; 5 int count = __; ^ 6 printf("%d\n", total / count); 7 return 0; 8 }
Floating point exception
空欄を埋めてコンパイル・実行を通す
int型を0で割ると、Cはこれを例外として捕まえられずプロセスごと強制終了します。countが0になり得る場合は、割る前に0でないことを確認する必要があります。
次の問題