C Hello World程序

Whenever we start to learn any programming language, “Hello World Program” is the first one where we learn the basic syntax. In this article, we will look into “C Hello World Program” and start our journey to learn C programming.

每当我们开始学习任何编程语言时,“ Hello World Program”都是我们学习基本语法的第一个语言。 在本文中,我们将研究“ C Hello World程序”,并开始学习C编程的旅程。

软体需求 (Software Requirement)

The following software(s) are required in the computer to begin with C programming.

要进行C编程,计算机中需要以下软件。

  1. Text Editor

    文本编辑器
  2. A “Text Editor” is software to write or modify plain text. We’ll be using it to write the Source Code of C program. There are several “text editors (e.g. Notepad, Code Writer etc.)” and “IDE’s (e.g. Eclipse, Codeblocks etc.)” available and you are free to choose from them.

    “文本编辑器”是用于编写或修改纯文本的软件。 我们将使用它来编写C程序的源代码。 有几种“文本编辑器(例如,记事本,代码编写器等)”和“ IDE(例如Eclipse,代码块等)”,您可以自由选择。

    Though, it is strongly advised to use a “Text Editor” instead of an IDE if you are new to C programming. We recommend Notepad++ or Microsoft Visual Studio Code for beginners.

    但是,如果您不熟悉C编程,则强烈建议使用“文本编辑器”代替IDE。 我们建议初学者使用Notepad ++Microsoft Visual Studio Code

  3. Compiler

    编译器
  4. A compiler is a tool which converts the “Source Code” of C program into “Machine Code” (also called as Executable Code). There are several C compilers available. We recommend using MINGW GCC Compiler.

    编译器是一种将C程序的“源代码”转换为“机器代码”(也称为可执行代码)的工具。 有几种可用的C编译器。 我们建议使用MINGW GCC编译器。

    Please refrain from using a very old compiler such as “Turbo C”. Also, note that the availability of multiple compilers of C doesn’t mean there are multiple C language(s). They would compile the C code almost the same way.
    You don’t need to go for technical and other differences of compilers and “versions of C” at this point; those are beyond the scope of this tutorial series.

    请避免使用非常老的编译器,例如“ Turbo C” 。 另外,请注意,多个C编译器的可用性并不意味着存在多种C语言。 他们将以几乎相同的方式编译C代码。
    此时,您无需寻求编译器和“ C版本”的技术差异和其他差异; 这些超出了本教程系列的范围。

    If you do not have “Text Editor” and “Compiler” installed and configured in your computer, refer to this article for the same. Follow steps carefully for your respective OS and configuration.

    如果你没有“文本编辑器”和“编译器”安装在你的电脑配置,请参阅文章一样。 对于您各自的操作系统和配置,请仔细执行以下步骤。

C Hello World程序 (C Hello World Program)

编写源代码 (Writing the Source Code)

Open the “Text Editor” which you have installed and type Source Code (avoid Ctrl+V or Copy Paste). Do not worry about understanding it at this time. We’ll be diving into every word and symbol of it very soon.

打开已安装的“文本编辑器”,然后键入源代码(避免使用Ctrl + V或“复制粘贴”)。 现在不用担心了解它。 我们很快就会深入到每个单词和符号。

#include <stdio.h>
void main()
{
    printf("Hello World");
}

Now save it with name as “HelloWorld” and extension “.c” i.e. “HelloWorld.c” on desktop or any folder/directory you like (e.g. ‘D:\Programming_In_C’).

现在保存为名称“ HelloWorld”和扩展名“ .c ”,即在桌面上或您喜欢的任何文件夹/目录(例如“ D:\ Programming_In_C”)中的“ HelloWorld.c”。

编译源代码 (Compiling the Source Code)

Assuming that you have the compiler installed and the PATH is configured, following the steps mentioned below.

假定您已安装编译器并且已配置PATH,请按照以下步骤操作。

Open Command Prompt (Windows) or Terminal (Unix/Linux/Mac) and go to the directory where you have saved the file ‘HelloWorld.c’ using cd command. Here we are showing how to do it in Windows.

打开命令提示符(Windows)或终端(Unix / Linux / Mac),然后转到使用cd命令保存文件“ HelloWorld.c”的目录。 在这里,我们展示了如何在Windows中执行此操作。

If the file ‘HelloWorld.c’ is saved in ‘D:\Programming_In_C’ folder, the commands would be:

如果文件“ HelloWorld.c”保存在“ D:\ Programming_In_C”文件夹中,则命令为:

  • D: and press Enter/Return key

    D:然后按Enter / Return键
  • cd D:\Programming_In_C and press Enter/Return key

    cd D:\ Programming_In_C并按Enter / Return键

Following the steps correctly would show the path of the directory where you have saved your file. To compile our source code, type this command in command prompt:

正确执行这些步骤将显示保存文件的目录路径。 要编译我们的源代码,请在命令提示符下键入以下命令:

  • gcc HelloWorld.c -o HelloWorld and press Enter/Return key.

    gcc HelloWorld.c -o HelloWorld ,然后按Enter / Return键。

If you have typed code and configured the compiler correctly, there should be no output. If there is some output(error) displayed at this point, fix this before proceeding further.

如果键入了代码并正确配置了编译器,则应该没有输出。 如果此时显示某些输出(错误),请在继续操作之前解决此问题。

In the command mentioned above;

在上述命令中;

  • gcc is name of the compiler.

    gcc是编译器的名称。
  • HelloWorld.c is name of file which would be compiled by the compiler.

    HelloWorld.c是将由编译器编译的文件的名称。
  • -o HelloWorld means that output file (which is Machine Executable Code) is saved by name “HelloWorld” (e.g. HelloWorld.exe in Windows). if -o is not given, file will be saved with name “a”.

    -o HelloWorld表示输出文件(它是机器可执行代码)以名称“ HelloWorld”保存(例如Windows中的HelloWorld.exe)。 如果未提供-o,则文件将以名称“ a”保存。

运行C Hello World程序 (Running the C Hello World Program)

Now in the same terminal or command prompt window, type HelloWorld and press Enter/Return key. You should see a output saying “Hello, World!”.

现在,在同一终端或命令提示符窗口中,键入HelloWorld并按Enter / Return键。 您应该看到一个输出,上面写着“ Hello,World!”。

Hello World C Compile Run

C Hello World C Program Run

C Hello World C程序运行

恭喜啦 (Congratulations)

You have successfully taken the first step of your learning path of C Programming. This is one-time process only and after this, we’ll start understanding and implementing the coding in C. If you facing any trouble in the installation or setting up compiler or editor, ask in comments with the error you are getting.

您已经成功地迈出了C编程学习道路的第一步。 这只是一个一次性的过程,此后,我们将开始理解和实现C语言中的编码。如果您在安装或设置编译器或编辑器时遇到任何麻烦,请在注释中询问您遇到的错误。

翻译自: https://www.journaldev.com/25311/c-hello-world

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值