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>
相关推荐
bluesky9612221 小时前
malloc 和 realloc C/C++
c语言·c++·算法
嵌入式小宁3 小时前
C11 原子操作 `atomic_int` 通俗指南
linux·c语言·嵌入式硬件
LuminousCPP3 小时前
数据结构-二叉树(三):堆复杂度证明与 Top-K 问题|错位相减推导 + 海量数据内存优化
c语言·数据结构·笔记·排序算法
吃杠碰小鸡19 小时前
VsCode中开发Java项目
java·vscode
qq_5896660520 小时前
C语言、C++与C#的区别详解
c语言·c++·c#
昌原的儿子LEO1 天前
Linux进程知识点总结
linux·服务器·c语言·数据库
2501_915106321 天前
Swift 开发环境搭建指南:三条路径按目标对号入座
开发语言·vscode·ios·objective-c·个人开发·swift·敏捷流程
thinking_talk1 天前
换一个 AI IDE,过去的数据还能继续用吗?
ide·ai ide·数据复用
Caster_Z1 天前
IntelliJ IDEA 安装 Qoder CN (Formerly Lingma)
java·ide·intellij-idea