中級 › error: assignment of read-only variable の原因と直し方 › パターン5
error: assignment of read-only variable の原因と直し方
constをつけて宣言した変数に、後から値を代入しようとしたときに出るエラーです。
1 #include <stdio.h> 2 3 int main(void) { 4 const double tax = 0.08; 5 _____________________ = 0.2; ^ 6 printf("%.2f\n", tax); 7 return 0; 8 }
main.c:5:9: error: assignment of read-only variable 'tax'
空欄を埋めてコンパイル・実行を通す
double型のconst変数でも同様です。値を変えたい場合は別の変数を用意します。
次の問題