当前位置:网站首页>Set sail C language, the first Hello World
Set sail C language, the first Hello World
2022-08-07 02:06:00 【Perfectkn】
目录
编译器
这里我选择的是Visual Studio 2013.
VS是一个非常完整的开发工具集,包括了所有软件生命周期中所需的大部分工具.
Preparation before writing code
打开VS2013





建立一个C源文件
After clicking New Item,会看到如下页面

Because the compiler defaults tocpp(即C++文件),你需要把cpp改成c(注意是小写)
更改后如下

这里我把“源”The word was changed tomain,It doesn't matter,想改就改,因为main是主函数的意思,When writing more files later,You can immediately find where the main file is.
Then click add.
第一个Hello World详细介绍
代码如下:
#include <stdio.h>
int main()
{
printf("Hello World!");
return 0;
}关于#include <stdio.h>
Q:#include <stdio.h>是一个头文件,So why have header files??
A:举个例子:like you go to college,You didn't bring your admission letter to report,The counselor doesn't know you either,Then you have to prove that you are a major in this school,Then you need to use the admission letter.
Q:That admission letter is equivalent to the header document,in that example“我”,相当于什么呢?
A:问的好,In the example I am in the code printf.因为写Cthose of the language,在#include <stdio.h>It helps you write the definition of this function,你直接拿来用就行了.
Q:Are all similar toprinf这样的函数,都在#include <stdio.h>Define it for me?
A:当然不是,When you use other functions later,You need to add other header files.
关于int main()
int是整型变量,what is an integer?is your math integer:负数、0、正数.
Q:main是什么?
A:问main不如直接说main(),Clanguage functions(),注意must be in English parentheses,main是C语言的主函数,Cwhere the language all programs begin,每个程序都从main开始运行.
Q:I see another{},这是什么?
A:上面说过main()Function is a place where all the program starts,Then you always have a range,put the program code in{}里,means running these programs.
关于printf()
printf()是打印函数,显而易见,just printing,As for the effect, it depends on the operation at the end of the article.
Q:()里的""Can it be omitted??
A:不可!In addition, when typing the code, be sure to switch to the input method English,Whether the brackets,引号,or comma,must be in English!Except you want to print Chinese characters,Chinese input method for Chinese characters.""The effect is that everything you need to print is in""里面.
Q:;是什么?
A:Add at the end of each line; 这是规定,Let the compiler to identify the end of a line.
关于return 0
Q:什么是return?
A:return是C语言的关键字.返回的意思.什么是关键字?int就是一个关键字,他是Clanguage default,such as once you enterreturn,The program knows to return.The return here also means the end.
Q:0呢?
A:还记得你在main之前写了个int吗,0和int对应,main前面的int表示返回值是整型,在main里面用intis to declare an integer variable.比如int ameans I declare a variable,它是整型的,And I didn't say his value,不固定,就是变量.
程序运行
VSThere is a shortcut key to run the program ctrl+F5 ,If the word is in laptopsctrl+fn+F5
看一下运行结果

From the pop-up window that appears in the running result,we want to printHello World!就出现了
Then you might want to ask again,I don't want the back“请按任意键继续”And I printed on the same line?
简单,在 ! 之后加一个\n即可.\n是C语言的换行符.

边栏推荐
猜你喜欢
随机推荐
工程仪器设备在线监测管理系统常见问题和注意事项
习题:循环结构(一)
decode()的用法
ansible Cron 模块
php generate pdf image to pdf
搭建Lua开发环境(Lua解释器+IDEA编译器)
进程线程的基本概念复习
【UGF】GameFramework接入HybridCLR(wolong)卧龙热更框架
FutureTask源码深度剖析
pytest合集(8)— API Functions
unity UI、 粒子 、3d模型,按钮如何设置显示
6-4 链式表的按序号查找(10分)
力扣169题,多数元素
接口项目实战
记一次To B开发普通的性能优化历程......报表优化
【8.5】代码源 - 【GCD】【序列中位数】【最大连边数量】
coco数据集解析及读取方法
神秘的程序员(1-20)
pycocotools库的使用
Unity UI, particle, 3d model, how to set the display button









