上級 › Assertion failed の原因と直し方 › パターン1
Assertion failed の原因と直し方
assert()に渡した条件式がその場でfalseになったときに強制終了するマクロです。
1 #include <stdio.h> 2 #include <assert.h> 3 4 int main(void) { 5 int score = 85; 6 assert(____________); ^ 7 printf("score=%d\n", score); 8 return 0; 9 }
main: main.c:6: main: Assertion `score > 100' failed.
Aborted
空欄を埋めてコンパイル・実行を通す
assert()は渡した条件式がその場でfalseになると強制終了します。scoreは85で100を超えていないのに「100より大きいはず」と誤った前提を書いてしまうと、プログラマ自身のロジックミスとして検出されます。
次の問題