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>
相关推荐
lss_dgr1 天前
vscode中ssh环境登录copilot没有反应的问题解决
ide·vscode·copilot
噜噜大王_1 天前
深入理解 C 语言内存操作函数:memcpy、memmove、memset、memcmp
c语言·开发语言
likerhood1 天前
简单工厂设计模式
java·ide·intellij-idea
chh5631 天前
C++--模版初阶
c语言·开发语言·c++·学习·算法
猫耳球团1 天前
IDEA与Cursor跨平台协作指南
java·ide·intellij-idea
jinyishu_1 天前
几道链表经典算法题
c语言·数据结构·算法·链表
算法鑫探1 天前
C语言入门:a和b 比大小
c语言·数据结构·算法·新人首发
云淡风轻__1 天前
在 VSCode 中配置 LaTeX 环境的保姆级教程
ide·vscode·编辑器
独隅1 天前
PyCharm 开启硬换行的方法
ide·python·pycharm
一只小小的土拨鼠1 天前
【国奖冲刺/全网首发】2026年第十四届“泰迪杯”A、B、C题完整解题思路、代码与高质量论文大合集
c语言·矩阵·数据挖掘