初級 › error: expected declaration or statement at end of input の原因と直し方 › パターン3
error: expected declaration or statement at end of input の原因と直し方
波括弧{}の対応が崩れ、閉じ忘れがあるときに出るエラーです。
1 #include <stdio.h> 2 3 int main(void) { 4 for (int i = 0; i < 3; i++) { 5 printf("%d\n", i); 6 _ ^ 7 return 0; 8 }
main.c:8:1: error: expected declaration or statement at end of input
空欄を埋めてコンパイル・実行を通す
for文も同じ罠があります。ループの{を閉じ忘れると、後続のコードがすべてループの中身として解釈されます。
次の問題