Hello, World!
Introduction 引言
The C programming language is a general purpose(通用的) programming language, which relates closely(密切地) to the way machines work. Understanding how computer memory works(计算机内存的工作原理) is an important aspect(方面) of the C programming language. Although C can be considered as(被认为是) "hard to learn", C is in fact(事实上) a very simple language, with very powerful capabilities(强大能力).
A of B : B的A
language lan gua ge 兰瓜哥
C is a very common language, and it is the language of many applications(许多应用程序) such as Windows, the Python interpreter(解释器), Git, and many many more(等等).
C is a compiled(编译) language - which means that in order to run it, the compiler(编译器) (for example, GCC or Visual Studio) must take the code that we wrote, process it, and then create an executable file(可执行文件). This file can then be executed(执行), and will do what we intended for(打算) the program to do.
Our first program
Every C program uses libraries(库), which give the ability to execute necessary functions. For example, the most basic function called printf
, which prints to the screen(屏幕), is defined(定义) in the stdio.h
header file(头文件).
To add the ability to run the printf
command to our program, we must add the following include directive(命令) to our first line of the code:
#include <stdio.h>
The second part of the code is the actual code which we are going to write. The first code which will run will always reside(驻留) in the main
function.
int main() {
... our code goes here
return 0;
}
The int
keyword indicates(表明) that the function main
will return an integer - a simple number. The number which will be returned by the function indicates whether the program that we wrote worked correctly. If we want to say that our code was run successfully, we will return the number 0. A number greater than(大于) 0 will mean that the program that we wrote failed.
For this tutorial(说明书), we will return 0 to indicate that our program was successful:
return 0;
Notice that every statement(每条语句) in C must end with a semicolon(分号), so that the compiler(编译器) knows that a new statement has started.
Last but not least(最后但同样重要的是), we will need to call the function printf
to print our sentence(句子).
Exercise 练习
Change the program at the bottom(底部) so that it prints to the output "Hello, World!".
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
}