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>
相关推荐
一路向北he4 小时前
trae或者vscode定义了文件,但是文件不亮是灰的
ide·vscode·编辑器
@yanyu6669 小时前
C编译器安装与第一个C程序
c语言·开发语言
山下梅子酒22510 小时前
洛谷-入门-B2070
c语言
Logic10110 小时前
C语言/数据结构位运算题解:异或XOR找出多任务下载器中的“独特下载速度“——只出现一次的数字
c语言·数据结构·数组·位运算·时间复杂度·算法题·异或性质
MI_farmer12 小时前
Anaconda 安装在 D 盘但虚拟环境跑到 C 盘,以及 Conda PermissionError: WinError 5 的解决方法
c语言·开发语言·conda
心中有你021413 小时前
C语言 二叉搜索树(BST)超详细完整实现(插入+查找+删除+三种遍历+内存释放)
c语言
神仙别闹13 小时前
基于C语言实现 TINY+ 编译器
c语言·开发语言·数据库
共享家952715 小时前
C语言-408
c语言·开发语言
VIP_CQCRE16 小时前
在 OpenCode IDE 中接入 Ace Data Cloud:让 VS Code、Cursor、Windsurf 都能调用统一 AI Coding 能力
vscode·ai编程·开发工具·opencode·acedatacloud
sunburn-17 小时前
Java 排序算法详细教学:从冒泡排序到快速排序
java·开发语言·数据结构·ide·算法