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>
相关推荐
WalterJau7 小时前
C 内存分区
c语言
csdn_aspnet9 小时前
C/C++ 两个凸多边形之间的切线(Tangents between two Convex Polygons)
c语言·c++·算法
yangtuoni11 小时前
vscode调试C++程序
c++·ide·vscode
剑心诀11 小时前
02 数据结构(C) | 线性表——顺序表的基本操作
c语言·开发语言·数据结构
m0_4886333212 小时前
Windows环境下编译运行C语言程序,合适工具与方法很关键
c语言·windows·git·开发工具·编译器
m0_4886333212 小时前
C语言变量命名规则、入门自学、运算符优先级及数据结构介绍
c语言·数据结构·运算符优先级·变量命名·入门自学
Book思议-12 小时前
【数据结构实战】川剧 “扯脸” 与栈的 LIFO 特性 :用 C 语言实现 3 种栈结构
c语言·数据结构·算法·
炸膛坦客15 小时前
单片机/C/C++八股:(二十一)include <> 和 include ““ 的区别
c语言·c++
Yupureki15 小时前
《Linux系统编程》12.基础IO
linux·运维·c语言·开发语言·数据库·c++
炸膛坦客15 小时前
单片机/C/C++八股:(十八)C/C++ 中 sizeof 和 strlen 的区别
c语言·c++