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>
相关推荐
tt5555555555553 分钟前
每日一题--数组中只出现一次的两个数字
c语言·数据结构·算法·leetcode
No8g攻城狮18 分钟前
【异常解决】在idea中提示 hutool 提示 HttpResponse used withoud try-with-resources statement
java·开发语言·ide·intellij-idea
funsion39 分钟前
Lua中文语言编程源码-第十一节,其它小改动汉化过程
c语言·开发语言·中文分词·lua
weixin_4561648341 分钟前
visual studio 2008的试用版评估期已结束的解决办法
ide·visual studio
kongba0071 小时前
c语言样式主题 清爽风格 代码色彩 keil风格 适合单片机开发GD32 STM32等 cursor或者vscode 的settings.json文件
c语言·vscode·stm32·单片机
我是唐青枫4 小时前
Jetbrains IDE http客户端使用教程
ide·网络协议·http
_未知_开摆5 小时前
运行npm install卡住不动的
前端·vue.js·vscode·elementui·npm·node.js
奇变偶不变07275 小时前
【C/C++】每日温度 [ 栈的应用 ] 蓝桥杯/ACM备赛
c语言·开发语言·数据结构·c++·算法·蓝桥杯
安小牛5 小时前
Android Studio 下载Gradle失败解决方法
android·ide·android studio
dilvx5 小时前
回退 android studio emulator 的版本
android·ide·android studio