第一个c语言程序_第一个C程序及其结构

第一个c语言程序

Lets see how to write a simple and most basic C program:

让我们看看如何编写一个简单且最基本的C程序:

#include <stdio.h>
int main()
{
 printf("Hello,World");  //single line comment
 return 0;
/*
    multi
    line
    comments
/*
}

Hello,World

你好,世界

C程序的不同部分 (Different parts of C program)

  • Pre-processor

    预处理器

  • Header file

    头文件

  • Function

    功能

  • Variables

    变数

  • Statements & expressions

    陈述与表达

  • Comments

    注释

All these are essential parts of a C language program.

所有这些都是C语言程序必不可少的部分。

预处理器 (Pre-processor)

#include is the first word of any C program. It is also known as a pre-processor. The task of a pre-processor is to initialize the environment of the program, i.e to link the program with the header files required.

#include是所有C程序的第一个字。 它也被称为预处理器 。 预处理器的任务是初始化程序的环境,即将程序与所需的头文件链接。

So, when we say #include <stdio.h>, it is to inform the compiler to include the stdio.h header file to the program before executing it.

因此,当我们说#include <stdio.h> ,是要通知编译器在执行程序之前将stdio.h头文件包含到程序中。

头文件 (Header file)

A Header file is a collection of built-in(readymade) functions, which we can directly use in our program. Header files contain definitions of the functions which can be incorporated into any C program by using pre-processor #include statement with the header file. Standard header files are provided with each compiler, and covers a range of areas like string handling, mathematical functions, data conversion, printing and reading of variables.

Header文件是内置(现成)函数的集合,我们可以在程序中直接使用它们。 头文件包含可以通过将预处理器#include语句与头文件一起使用而合并到任何C程序中的功能的定义。 每个编译器都提供了标准头文件,它涵盖了一系列领域,例如字符串处理,数学函数,数据转换,打印和读取变量。

With time, you will have a clear picture of what header files are, as of now consider as a readymade piece of function which comes packaged with the C language and you can use them without worrying about how they work, all you have to do is include the header file in your program.

随着时间的流逝,您将清楚地了解什么是头文件,到目前为止,您可以将其视为C语言附带的现成函数,您可以使用它们而不必担心它们的工作原理,您所要做的就是在程序中包含头文件。

To use any of the standard functions, the appropriate header file must be included. This is done at the beginning of the C source file.

要使用任何标准功能,必须包含适当的头文件。 这是在C源文件的开头完成的。

For example, to use the printf() function in a program, which is used to display anything on the screen, the line #include <stdio.h> is required because the header file stdio.h contains the printf() function. All header files will have an extension .h

例如,要在用于在屏幕上显示任何内容的程序中使用printf()函数,由于头文件stdio.h包含printf()函数,因此需要行#include <stdio.h> 。 所有头文件都将具有扩展名.h

主功能 (main() function)

main() function is a function that must be there in every C program. Everything inside this function in a C program will be executed. In the above example, int written before the main() function is the return type of main() function. we will discuss about it in detail later. The curly braces { } just after the main() function encloses the body of main() function.

main()函数是每个C程序中都必须存在的函数。 C程序中此函数内部的所有内容都将执行。 在上面的示例中,在main()函数之前编写的intmain()函数的返回类型 。 我们将在后面详细讨论。 大括号{ }main()函数封装main()函数的身体之后。

We will learn what functions are in upcoming tutorials.

我们将在以后的教程中学习什么功能。

注释 (Comments)

We can add comments in our program to describe what we are doing in the program. These comments are ignored by the compiler and are not executed.

我们可以在程序中添加注释以描述我们在程序中正在做什么。 这些注释将被编译器忽略,并且不会执行。

To add a single line comment, start it by adding two forward slashses // followed by the comment.

要添加单行注释,请先添加两个正斜杠//然后再添加注释。

To add multiline comment, enclode it between /* .... */, just like in the program above.

要添加多行注释,请将其括在/* .... */ ,就像上面的程序一样。

返回语句-返回0; (Return statement - return 0;)

A return statement is just meant to define the end of any C program.

return语句仅用于定义任何C程序的结尾。

All the C programs can be written and edited in normal text editors like Notepad or Notepad++ and must be saved with a file name with extension as .c

所有C程序都可以在普通文本编辑器(如Notepad或Notepad ++)中进行编写和编辑,并且必须使用扩展名为.c的文件名进行保存。

If you do not add the extension .c then the compiler will not recognise it as a C language program file.

如果不添加扩展名.c则编译器将不会将其识别为C语言程序文件。

编写您的第一个C程序 (Writing your first C Program)

In the video below we have explained stepwise how to write your first C program, compile it and run it.

在下面的视频中,我们逐步说明了如何编写,编译和运行第一个C程序。

演示地址

翻译自: https://www.studytonight.com/c/first-c-program.php

第一个c语言程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值