C语言Hello World程序 Code 例如:

C语言的Hello World程序
这是一个用 C 语言编写的 Hello World 程序
#include<stdio.h> // Pre-processor commands void main() { printf("Hello World\n"); // Print Hello World on the screen }
以下是代码解释:
预处理指令
#include is a pre-processor directive in 'C.'
#包括,stdio 是该函数所在的库 的printf printf 函数用于生成输出。在使用此函数之前,我们必须先包含所需的头文件(.h)。
您还可以创建自己的函数,将它们分组到头文件中,并在程序顶部声明它们以使用它们。要在程序中包含文件,请使用预处理器指令
#include <file-name>.h
文件名是存储函数的文件的名称。预处理器指令始终位于程序的开头。
主要功能
The main function is a part of every 'C' program. We can represent the main function in various forms, such as:
- 主()
- int main()
- void main()
- 主要(无效)
- 无效的主要(无效)
- int main(void)
空括号表示此函数不接受任何参数、值或参数。您也可以通过在括号内放置关键字 void 来明确表示这一点。
#include<stdio.h> // Pre-processor directive int main() // main function declaration { printf("Hello World"); // to output the string on a display return 0; // terminating function }
在上面的例子中,关键字 int 表示函数将返回一个整数值。在这种情况下,最后一条语句应该始终返回 0。
源代码
声明主函数后,我们必须指定左括号和右括号。 花括号 { }, 表示程序的开始和结束。这些括号必须始终放在 main 函数之后。所有程序代码(包括声明部分和可执行部分)都写在这些括号内。
此 的printf function generates the output by passing the text "Hello World!"
此 分号; 确定语句的结束。在 C 语言中,每个语句必须以分号结尾。
这样我们就成功安装了 编译 and now can begin working in 'C.' We will write a simple program that will say hello to us. Let's start.
如何运行 C 程序
步骤1) 创建新项目
步骤2) 在弹出窗口中,
- 选择文件
- Choose the "C/C++ Source"
- Click "Go."
步骤3) Continue, by clicking on "Next."
步骤4) To create the new file, select a "C" file then click on "Next" button to continue.
步骤5) Set the file path by clicking the "..." button, the explorer window permits to create the C file.
步骤6) 选择新 C 文件的路径,然后选择其名称(扩展名为 .c)并保存。
步骤7) Finally, to confirm the C file creation click "Finish."
步骤8) Enter the code, save it and compile it by clicking on the "Build & Run "button.
结果如下:
Hello, World!








