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>
相关推荐
luj_176823 分钟前
马克思的跨学科学术体系
c语言·开发语言·c++·经验分享·算法
Byte Wizard2 小时前
C语言文件操作
c语言·开发语言
Zephyrus_20232 小时前
LSM6DSV16X驱动移植+调试
c语言·arm开发
yongridada2 小时前
公司内网使用Vscode+claude code
vscode·claude code
阿林爱吃大米饭3 小时前
VSCode Remote SSH 内网服务器使用Codex插件 + Codex跨Provider历史会话迁移完整教程
服务器·vscode·ssh
hope_wisdom3 小时前
C/C++数据结构之二叉树基础
c语言·数据结构·c++·二叉树
Chen_harmony3 小时前
二十五、预处理详解
c语言
高级打杂工程师-伍六六3 小时前
想随时随地做点自己的事?创建一台VSCode登录的云电脑
人工智能·vscode
2023自学中3 小时前
Linux虚拟机,VSCode + GDB 调试配置:launch.json 模板
linux·vscode·嵌入式