vscode中使用code-runner插件运行c程序语法报错code: 1

代码

复制代码
int main() {
    // 定义变量a,赋值为10
    int a = 10;
    // 定义变量b,赋值为20
    int b = 20;
    // 定义变量c,将a和b相加的结果赋值给c
    int c = a + b;
    // 输出c的值
    printf("%d", c);
    // 返回0,表示程序正常结束
    return 0;
}

问题:

vscode中使用code-runner插件允许c程序报错:

复制代码
[Running] cd "d:\dev\c\study\" && gcc demo1.c -o demo1 && "d:\dev\c\study\"demo1
demo1.c: In function 'main':
demo1.c:9:5: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
    9 |     printf("%d", c);
      |     ^~~~~~
demo1.c:1:1: note: include '<stdio.h>' or provide a declaration of 'printf'
  +++ |+#include <stdio.h>
    1 | int main() {
demo1.c:9:5: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
    9 |     printf("%d", c);
      |     ^~~~~~
demo1.c:9:5: note: include '<stdio.h>' or provide a declaration of 'printf'

[Done] exited with code=1 in 0.239 seconds

原因

未添加c头文件

复制代码
#include <stdio.h>
相关推荐
aramae1 小时前
模拟实现strcmp()(C语言)
c语言·开发语言·后端
程序员允诺3 小时前
内网/无网环境必备:VS Code Remote-SSH 离线包下载与手动部署教程
vscode
滕州市燕猫虎计算机科技工作室个体工商户6 小时前
IDEA:Command line is too long
java·ide·intellij-idea
91刘仁德10 小时前
C++ 继承和多态 设计模式
c语言·c++·笔记
码行山野赴时序归途10 小时前
链表家族收官篇:循环链表
c语言·开发语言·数据结构·链表
darin_ฅ( ̳• ◡ • ̳)ฅ110 小时前
【开发工具】2026版-VScode&IDEA&Cursor插件安装及插件配置迁移
vscode·idea
库玛西10 小时前
哈夫曼树与前缀编码:数据压缩的贪心核心
c语言·c++·笔记·考研
别动我齐刘海10 小时前
ROS2 Jazzy + C++ 实战路线——进阶学习3
c++·人工智能·vscode·python·算法·机器学习·机器人
雷✘11 小时前
C 语言预处理中的宏展开、条件编译与头文件保护
c语言
aramae11 小时前
模拟实现memset()(C语言)
c语言·开发语言·后端