初級 › Segmentation fault(NULLポインタの参照) › パターン4
Segmentation fault(NULLポインタの参照)
NULL(何も指していないポインタ)の指す先を読み書きしようとしたときに発生するクラッシュです。
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(void) { 5 int total = 0; 6 int *ptr = ___________________; ^ 7 total += *ptr; 8 printf("%d\n", total); 9 return 0; 10 }
Segmentation fault
空欄を埋めてコンパイル・実行を通す
ptrがNULLのまま*ptrを読み取ろうとするとクラッシュします。
次の問題