初級 › error: initialization of 'char' from 'char *' makes integer from pointer without a cast の原因と直し方 › パターン1
error: initialization of 'char' from 'char *' makes integer from pointer without a cast の原因と直し方
1文字を表すchar型の変数に、ダブルクォートで囲んだ文字列リテラルを代入しようとしたときに出るエラーです。
1 #include <stdio.h> 2 3 int main(void) { 4 char grade = ___; ^ 5 printf("%c\n", grade); 6 return 0; 7 }
main.c:4:18: error: initialization of 'char' from 'char *' makes integer from pointer without a cast [-Wint-conversion]
空欄を埋めてコンパイル・実行を通す
"A"はA1文字とその後の終端文字からなる文字列(char*型)です。1文字だけを表すchar型に代入するにはシングルクォートの'A'を使います。
次の問題