Visual Studio Code下载与安装Visual Studio Code是微软推出的一款开源、跨平台(windows,Ubuntu,macOS)的编辑器,这里使用它来编写C语言的源代码,当然除了编写C代码之外,还可以用来编写C++,JAVA,Python,Go,JavaScript,php程序等等 。
为什么首先使用Visual Studio Code来编写C程序而不是功能强大的Visual Studio 2019来实现呢
因为作为一位初学者来讲,应该要理解程序运行的背后机制,而Visual Studio 2019封装了大量的细节,不便于初学者理解,在后期进行项目开发时可以选用Visual Studio 2019作为C语言的开发工具 。
在使用Visual Studio Code之前首先去官网下载

文章插图
然后傻瓜一键式安装,安装完成以后启动Visual Studio Code会看到启动界面 。

文章插图
启动界面
关于Visual Studio Code的详细使用可以参考官方提供的文档 。
使用Visual Studio Code编辑源文件因为windows10默认不显示文件后缀名,这里直接在Visual Studio Code中编辑源文件可以避免该问题,同时也可以在文件资源管理器中勾选文件扩展名,这样当我们在文件系统中查看文件时可以看到文件的后缀名 。

文章插图
1.在系统的D盘下创建目录vs_codec用于存放C语言的源程序(即C代码)
2.在Visual Studio Code中将D:vs_codec目录添加到工作区的文件夹

文章插图
选择D:vs_codec文件夹作为Visual Studio 2019开发C程序的工作区

文章插图
3.在工作区D:vs_codec目录下创建源文件helloworld.c,C语言的源文件都是以.c结尾的,并编写以下内容
#include <stdio.h>int main(int argc, char *argv[]){printf("Windows10 1903 & Visual Studio Code Hello World With C n");return 0;}

文章插图
helloworld.c
使用GCC编译器编译C程序GCC安装与配置当源文件编辑好完成以后,需要安装和配置gcc来编译C程序,因为Visual Studio Code并没有提供编译C程序的功能 。
如果你之前已经下载安装过Qt,那么恭喜不用额外安装gcc,因为Qt已经集成了编译器 。
只需要将gcc在Qt的 C:QtQt5.13.0Toolsmingw730_64bin目录: 添加至PATH环境变量即可 。

文章插图
当在终端上执行gcc命令时系统会从该目录寻找gcc对应的可执行程序gcc.exe 。

文章插图
当gcc的PATH环境变量配置成功之后,便可以打开命令提示符(即终端),输入gcc -v便可查看gcc版本信息

文章插图
GCC编译源文件在源文件helloworld.c所在的目录地址栏(例如D:vs_codec)输入cmd并回车即可打开终端,此时终端的路径正好是在D:vs_codec,然后使用gcc helloworld.c 编译源文件,Windows上gcc默认会编译生成可执行文件a.exe,linux下gcc默认会编译生成a.out 。

文章插图
然后在终端上运行a.exe,程序会将字符串Windows10 1903 & Visual Studio Code Hello World With C输出到终端上 。

文章插图
如果想要改变编译生成的可执行文件名称,使用gcc时可以使用-o选项实现
gcc helloworld.c -o helloworld.exe

文章插图
gcc helloworld.c -o helloworld.exe
【C语言核心技术-使用Visual Studio Code和GCC开发C程序】
推荐阅读
- 编程核心知识—API与ABI的区别
- 计算机基本原理—语言与算法
- APP是怎么给你推荐你喜欢的内容的?
- 三款自制纤腿瘦身茶推荐
- 北斗卫星技术介绍 发射北斗卫星的意义
- 有机茶生产技术操作规程介绍
- 有效发菌技术助力台湾茶业迈向全新世界之路
- 制茶技术流 新北市制茶达人黄文雄屡获大奖
- C 语言和 C++、C# 的区别在什么地方?
- 建德苞茶的种植繁育技术介绍