You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决C语言报错:incompatible type for argument 1 of 'printf'

报错原因

C标准库中printf函数的第一个参数要求是const char*类型的格式控制字符串,你直接传入了float类型的变量w,参数类型不匹配,因此触发了该编译错误。

修复方案
  • 首先补充格式控制串,float类型对应的格式占位符为%f,需要打印的变量放在printf的第二个参数位置即可,正确写法如下:
    printf("%f", w);
  • 如果你需要指定输出的小数位数,比如保留2位小数,可以调整格式占位符的写法:
    printf("%.2f", w);
完整修正代码
#include <stdio.h>
#include <stdlib.h>

static float w = 10.00;

int main()
{
    printf("%f", w);
    return 0;
}

内容的提问来源于stack exchange,提问作者Randy Chen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 21:24:01