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>
相关推荐
lcj251127 分钟前
深入理解指针(4):qsort 函数 & 通过冒泡排序实现
c语言·数据结构·算法
CS创新实验室1 小时前
Pandas 3 的新功能
android·ide·pandas
-嘟囔着拯救世界-1 小时前
【2026 最新版】OpenAI 祭出王炸 GPT-5.3-Codex!Win11 + VSCode 部署保姆级教程
vscode·gpt·chatgpt·node.js·node·codex·gpt5
4311媒体网1 小时前
C语言操作符全解析 C语言操作符详解
java·c语言·jvm
二年级程序员2 小时前
一篇文章掌握“顺序表”
c语言·数据结构
傻乐u兔2 小时前
C语言进阶————指针4
c语言·开发语言
历程里程碑3 小时前
Linux22 文件系统
linux·运维·c语言·开发语言·数据结构·c++·算法
2601_9491465310 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
知南x12 小时前
【Ascend C系列课程(高级)】(1) 算子调试+调优
c语言·开发语言
2的n次方_14 小时前
Runtime 执行提交机制:NPU 硬件队列的管理与任务原子化下发
c语言·开发语言