c入门教程_C入门

c入门教程

C++ is a cross-platform language that can be used to create applications. It’s an extension of C language. It’s a middle-level language rendering its advantage of programming low-level and high-level applications. It’s one of the predominant languages for the development of all kinds of technical and commercial software.

C ++是一种可用于创建应用程序的跨平台语言。 它是C语言的扩展。 它是一种中级语言,具有对低级和高级应用程序进行编程的优势。 它是开发各种技术和商业软件的主要语言之一。

C++ is an Object-Oriented Programming language and follows the OOPs concept of Data Abstraction, Data Hiding, Encapsulation, Polymorphism, and Inheritance. The language uses real-life concepts to develop a program. Being an Object-Oriented Language helps to make maintainable and extensible programs. The programs made from this language are easy to modify and easy to understand.

C ++是一种面向对象的编程语言,它遵循OOP的数据抽象,数据隐藏,封装,多态性和继承的概念。 该语言使用现实生活中的概念来开发程序。 成为一种面向对象的语言有助于制作可维护和可扩展的程序。 用这种语言制作的程序易于修改和易于理解。

Image for post

C++ has rich library support allowing easy access to functions that are very common for developers to use. It also has an extensive collection of header files necessary for a program to work. There is always a need of a “main()” function for the program’s main functional body which stores the commands to be first executed.

C ++具有丰富的库支持,可以轻松访问开发人员常用的功能。 它还具有程序运行所需的头文件的大量集合。 程序的主要功能主体始终需要“ main()”功能,该功能存储要首先执行的命令。

Image for post

C++ isn’t a very hard language for as long as you approach it in a stepwise manner. The language uses easy to understand commands and the codes are kind of user-friendly, so it’s easy to work on a C++ application.

只要您逐步使用C ++,它就不是一种很难的语言。 该语言使用易于理解的命令,并且代码易于使用,因此可以在C ++应用程序上轻松工作。

The very basic program of C++ language is to print “Hello World!”, for which the code is as follows :-

C ++语言最基本的程序是打印“ Hello World!”,其代码如下:-

Image for post

Now you all might be looking at this program and thinking,” what is this?”, well, let’s get to some explanations.

现在大家可能都在看这个程序,然后思考“这是什么?”,那么,让我们进行一些解释。

头文件 (Header Files)

In the starting 2 lines, there are two different “Header Files”. Here, “#include” is used to give a command to the computer to include the header files given in brackets and “<iostream.h>” and “<conio.h>” are those header files. Header files are necessary components of a program, without them, the program won’t work. Header files are a library of inbuilt (already built within) functions, when a header file is used in a program, all the functions of that header file’s library (used within the program) work. In the above program, “cout” and “endl” are inbuilt functions of “<iostream.h>” header file and “clrscr()” and “getch()” are inbuilt functions of “<conio.h>” header file.

在前两行中,有两个不同的“头文件” 。 此处, “#include”用于向计算机发出命令,以包括方括号中给出的头文件,而“ <iostream.h>”“ <conio.h>”是这些头文件。 头文件是程序的必要组成部分,如果没有它们,程序将无法运行。 头文件是内置(已内置)函数的库,当在程序中使用头文件时,该头文件的库(在程序内使用)的所有功能均起作用。 在上述程序中, “ cout”“ endl”“ <iostream.h>”头文件的内置函数,而“ clrscr()”“ getch()”“ <conio.h>”头文件的内置函数。

Image for post

~> The function “cout” performs printing of the text written within the symbols “ ” . It’s a function of “<iostream.h>” header file and is used with insertion operator “<<”.

〜>函数“ cout”执行打印写在符号“”内的文本。 它是“ <iostream.h>”头文件的功能,与插入运算符“ <<”一起使用

Image for post

Syntax for cout :- cout<<” “; (if any text were input in-between “ “, then the program will output the text)

cout的语法: -cout <<”“; (如果在“”之间输入了任何文本,则程序将输出文本)

~> The function “endl” is used to jump to another line after printing the text given in “ “ or just leave a line without printing any text. It’s also a function of “<iostream.h>” and is always used with “cout”. An alternative of “endl” is “\n” , which is written within symbols “ “ .

〜>函数“ endl”用于在打印“”中给出的文本后跳至另一行,或仅保留一行而不打印任何文本。 它也是“ <iostream.h>”的函数,始终与“ cout”一起使用“ endl”的替代形式是“ \ n” ,它写在符号“”中。

Image for post

Syntax for endl :- cout<<endl; (This will leave a line without printing anything)

endl的语法: -cout << endl; (这将使行不打印任何内容)

cout<<”Hello”<<endl; (This will jump to another line after printing “Hello”)

cout <<“ Hello” << endl; (在打印“ Hello”后,它将跳到另一行)

Syntax for \n :- cout<<”\n”; (This will leave a line without printing anything)

\ n的语法: -cout <<” \ n”; (这将使行不打印任何内容)

cout<<”Hello \n”; (This will jump to another line after printing “Hello”)

cout <<“你好\ n”; (在打印“ Hello”后,它将跳到另一行)

~> The function “clrscr()” clears the output last executed and provide an empty space for new execution. It’s the function of “<conio.h>” header file. It’s normally placed at the start of a program to get an empty space but it can be placed anywhere in the code as per user’s need to get the most favorable output.

〜>函数“ clrscr()”清除上次执行的输出,并为新的执行提供空白空间。 它是“ <conio.h>”头文件的功能。 通常将其放置在程序的开头以获取空白,但可以根据用户的需要将其放置在代码中的任何位置,以获取最有利的输出。

Image for post

Syntax for clrscr() :- clrscr(); (semicolon is must, otherwise there will be an error)

clrscr()的语法: -clrscr(); (必须使用分号,否则将出现错误)

~> The function “getch()” kind of holds the output screen for the user to see the output. It’s the function of “<conio.h>” header file. If this function is not used then the output screen will appear only for a moment of milliseconds and then disappear, like a flash or blink. It’s normally placed at the end of the program but it can also be placed anywhere in the code as per user’s need to get favorable output.

〜>函数“ getch()”将保留输出屏幕,以供用户查看输出。 它是“ <conio.h>”头文件的功能。 如果不使用此功能,则输出屏幕将仅出现一毫秒,然后消失,如闪烁或闪烁。 通常将其放置在程序的末尾,但也可以根据用户的需要将其放置在代码中的任何位置,以获取令人满意的输出。

Image for post

Syntax for getch():- getch(); (semicolon is must, otherwise there will be an error)

getch()的语法: -getch(); (必须使用分号,否则将出现错误)

主功能 (Main Function)

main() is a function that is must for a C++ program to work, without this function, the program won’t work at all because this function holds the main body of the program. The execution of a program starts and ends at the main(), without main() there won’t be any start for the execution of the program. A program can contain many functions but one of them has to be main(), but if a program has only one function then it must be main().

main()是C ++程序必须运行的函数,如果没有该函数,该程序将根本无法工作,因为该函数拥有程序的主体。 程序的执行在main()处开始和结束,没有main()的情况下,程序的执行就不会有任何开始。 一个程序可以包含许多功能,但是其中一个功能必须是main(),但是如果一个程序只有一个功能,则它必须是main()。

Image for post

In front of the main(), the word “void” refers to the “Return type” of this function. The return type of main() can be int, float, double, and so on, depending on the user’s choice. “Return type” refers to the kind of value which the program will give back after the execution of the whole program. Here, “void” indicates that no value is needed to be returned while “int”, “float”, “double” and so on indicates that a value is needed to be returned and the returned value should be of the type specified in front of main().

在main()前面,单词“ void”是指此函数的“返回类型” 。 main()的返回类型可以是int,float,double等,具体取决于用户的选择。 “返回类型”是指程序在执行完整个程序后将返回的值的类型。 在此,“ void”表示不需要返回任何值,而“ int”,“ float”,“ double”等则表示需要返回一个值,并且返回的值应为前面指定的类型。 main()。

程序主体 (Body of Program)

Body of the program consists of working/executable part of the program, given by the user to get a favorable output. Within the body, declaration of variables is made, commands for printing and input is given, values are assigned, and so on. The body of the program is basically a user’s idea put in words and commands to get an output.

程序的主体由程序的工作/可执行部分组成,由用户给出以获得满意的输出。 在主体内进行变量的声明,给出用于打印和输入的命令,分配值,等等。 程序的主体基本上是用户的想法,可以通过单词和命令来获得输出。

Image for post

分号(;) (Semicolon (;))

Semicolon is one of the most important parts of C++ programming as it marks the end of a line or code. If not put at the end of required lines, then during compiling and execution there will be errors.

分号是C ++编程中最重要的部分之一,因为它标志着一行或代码的结尾。 如果未放在必需行的末尾,则在编译和执行过程中将出现错误。

Image for post
Image for post
Image for post

开始和结束括号 (Starting and Ending Parenthesis)

Starting parenthesis “ { “ and Ending parenthesis “ } “ marks the start and end of the body of the program or function. Within these parentheses, the written code will be executed and the code will be the part of only that particular function (if another function is made other than main() ).

起始括号“ {”和结束括号“}”标记程序或函数主体的开始和结束。 在这些括号内,将执行编写的代码,并且该代码将仅是该特定功能的一部分(如果使用main()以外的其他功能)。

Image for post
Image for post

上面给出的代码输出(Output of the code given above :-)

Image for post

Well, let’s summarize all the topics covered in this explanation :-

好吧,让我们总结一下这个解释中涵盖的所有主题:

~> C++ :- A middle-level language used to program low-level and high-level user-friendly programs/applications.

〜> C ++ :-一种中级语言,用于对低级和高级用户友好型程序/应用程序进行编程。

~> Header Files :- A library of inbuilt functions used within the program.

〜> 头文件 :-程序中使用的内置函数库。

~> Main Function :- main() is a necessity for the program, which contains the body and executable part of the program.

〜> Main Function :-main()是程序的必需项,它包含程序的主体和可执行部分。

~> Body of Program :- The executable/working part of the program, which when executed gives an output.

〜> 程序主体 :-程序的可执行/工作部分,执行时给出输出。

~> Starting parenthesis “ { “ & Ending parenthesis “ } “ :- To mark start and end of the body of the program.

〜> 起始括号“ {“和结束括号“}” :-标记程序主体的开始和结束。

This sums up all the explanation for today.

总结了今天的所有解释。

If you have any questions or queries regarding any topic, then please do let me know in the comments. I will try my best to solve that problem of yours.

如果您对任何主题有任何疑问或疑问,请在评论中让我知道。 我将尽力解决您的问题。

Be tuned for the next part which will cover a new program with some new topics.

敬请关注下一部分,该部分将介绍具有一些新主题的新程序。

翻译自: https://medium.com/swlh/introduction-to-c-d8487697172e

c入门教程

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值