Code Fix

中級error: assignment of read-only variable の原因と直し方 › パターン3

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

constをつけて宣言した変数に、後から値を代入しようとしたときに出るエラーです。

 1  #include <stdio.h>
 2  
 3  int main(void) {
 4      const double rate = 0.05;
 5      __________________ = 0.1;
                 ^
 6      printf("%.2f\n", rate);
 7      return 0;
 8  }
main.c:5:10: error: assignment of read-only variable 'rate'

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

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

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

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

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

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