本文へスキップ
BecomeCoder

C言語のエラー · エラー3

format '%d' expects ... ― printf の書式と型が合わない

printf/scanf の変換指定子(%d など)と引数の型がずれると出ます。

出るコード

double x = 3.14;
printf("%d\n", x);   // double を %d で出そうとした

エラーメッセージ

warning: format '%d' expects argument of type 'int', but argument 2 has type 'double' [-Wformat=]

直し方

型に合う指定子を使います(double%f)。整数は %d文字列%s