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>
相关推荐
coding消烦员6 小时前
新版 vscode 去除快捷键 Ctrl+I 显示 Copilot 的 AI 对话框
人工智能·vscode·copilot
Yupureki6 小时前
从零开始的C++学习生活 16:C++11新特性全解析
c语言·数据结构·c++·学习·visual studio
ScilogyHunter7 小时前
C语言标准库完全指南
c语言·开发语言
程子的小段8 小时前
C 语言实例 - 字符串复制
c语言·开发语言
是苏浙9 小时前
零基础入门C语言之深入了解指针2
c语言·开发语言
农场主John9 小时前
vscode断点使用
ide·vscode·编辑器
Caesar Zou10 小时前
解决 Codex 在 WSL/SSH/VSCODE 登录时报 “Token exchange failed: 403 Forbidden” 问题
ide·vscode·编辑器
一念&10 小时前
每日一个C语言知识:C 预处理器
c语言·算法
hazy1k10 小时前
51单片机基础-I²C通信与EEPROM读写
c语言·stm32·单片机·嵌入式硬件·51单片机·1024程序员节