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>
相关推荐
从零开始的嵌入式之旅3 分钟前
day33
linux·c语言·经验分享·笔记·嵌入式硬件
2401_8628808231 分钟前
Linux应用层开发 --- 管道
linux·运维·c语言
Navigator_Z2 小时前
LeetCode //C - 1220. Count Vowels Permutation
c语言·算法·leetcode
洛兮银儿2 小时前
pycharm选中同一个词的标记颜色的修改
ide·python·pycharm
彷徨而立2 小时前
【C/C++】多线程读写普通 int 变量的一些问题
java·c语言·c++
2601_962381582 小时前
VSCode如何配置LlamaIndex RAG(检索增强生成)应用开发环境
vscode·开发环境·rag·llamaindex·检索增强生成
小灰灰搞电子3 小时前
分享自己写的一个通信协议源码,支持C++和C,双包头+不定长
c语言·开发语言·c++
bu_shuo3 小时前
Linux中修改demo.c文件的权限
linux·c语言
luj_17683 小时前
断舍离中的项目管理智慧
c语言·开发语言·c++·经验分享·算法
春风解人意4 小时前
从零开始学习嵌入式P30----进程间的通信
c语言·学习