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>
相关推荐
mit6.82417 分钟前
[邮件服务器core] 安全通信(SSL/TLS) | OpenSSL库管理 | 服务端安全SECURITY.md
c语言·github
Lecxcy_Kastreain27 分钟前
解决VSCode默认F5配置无法启动调试器的问题
ide·vscode·编辑器
长安——归故李28 分钟前
【modbus学习】
java·c语言·c++·学习·算法·c#
胡乱编胡乱赢2 小时前
在pycharm终端安装torch
ide·深度学习·pycharm·安装torch
梁小憨憨2 小时前
PyCharm 连接 AutoDL 远程服务器
服务器·ide·pycharm
T0uken2 小时前
【C++】LLVM-mingw + VSCode:Windows 开发攻略
c++·windows·vscode
草莓熊Lotso5 小时前
《算法闯关指南:优选算法-双指针》--01移动零,02复写零
c语言·c++·经验分享·算法·leetcode
一骑红尘荔枝来6 小时前
转载:VSCODE 关闭文件和资源管理器关联
ide·vscode·编辑器
float_六七8 小时前
IntelliJ IDEA双击Ctrl的妙用
java·ide·intellij-idea
android_xc10 小时前
Android Studio国内仓库配置
android·ide·android studio