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>
相关推荐
Dlrb12111 天前
C语言-指针三
c语言·算法·指针·const·命令行参数
kkeeper~1 天前
0基础C语言积跬步之深入理解指针(5下)
c语言·开发语言
三品吉他手会点灯1 天前
C语言学习笔记 - 40.数据类型 - scanf函数的编程规范与非法输入处理
c语言·开发语言·笔记·学习
♛识尔如昼♛2 天前
C 进阶(9) - 信号
c语言·信号
qeen872 天前
【算法笔记】各种常见排序算法详细解析(下)
c语言·数据结构·c++·笔记·学习·算法·排序算法
VIV-2 天前
Pycharm项目上传到Github
ide·pycharm·github
OsDepK2 天前
AudioSplit音频多轨免费分离工具即将发布
ide·git·python·音视频·集成学习
Legendary_0082 天前
解析 PD Sink 与 LDR6500U:Type-C 取电的核心密码
c语言·开发语言
xingyuzhisuan2 天前
Jupyter Notebook 云GPU配置全解析(含实操+选型指南)
ide·python·jupyter·gpu算力
basketball6162 天前
C++ 强制类型转换:从 C 风格到 C++ 四大金刚
java·c语言·c++