Code Fix

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

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

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

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

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

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

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

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

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

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