Code Fix

中級 › 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'

空欄を埋めてコンパイル・実行を通す

広告
広告スロット(未設定)

error: assignment of read-only variable の原因と直し方

constは「一度決めたら変更不可」を意味します。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)