Hello, World!

本文介绍了C语言的基本概念,强调了其与计算机内存工作原理的紧密关系。C语言虽被认为难学,但其实非常简洁且功能强大。文章通过一个简单的例子,指导读者编写并理解第一个C程序——打印Hello,World!。程序涉及#include预处理指令、main函数、返回值以及printf函数的使用。通过这个练习,初学者可以开始掌握C语言的基础语法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yangbocsu

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值