Hello guys, Welcome. Thanks for clicking on this article. Hope you learn some stuff from my stories. Lets get started!
大家好,欢迎光临 感谢您点击这篇文章。 希望你从我的故事中学到一些东西。 让我们开始吧!
C is a general-purpose programming language. It has been closely related with UNIX operation system (an opensource alternative to windows). When UNIX was developed, both the OS and applications that run on it are written in C. Through it has been called as “System Programming language” because it is useful for writing compiles and operating system. It has been used equally well to write major programs in different domains.
C是一种通用编程语言。 它与UNIX操作系统(Windows的开源替代品)密切相关。 在开发UNIX时,操作系统和在其上运行的应用程序都用C编写。通过它被称为“ 系统编程语言 ”,因为它对于编写编译器和操作系统很有用。 它同样被用来在不同领域编写主要程序。
For many years, the definition of ‘C’ was a reference manual in the first edition of “The Programming Language” in 1983 later the AMERICAN NATIONAL STANDARD INSTITUTE (ANSI) established a committee to provide modern comprehensive definition to C. The resulting definition was ANSI standards of ANSI ‘C’ was completed late in 1988. Modern compilers already support most of the features of standards.
多年来,“ C”的定义一直是1983年第一版“ 编程语言”中的参考手册,后来美国国家标准学会 ( ANSI )成立了一个委员会,为C提供现代的全面定义。 ANSI C的ANSI标准于1988年末完成。现代编译器已经支持该标准的大多数功能。
Over the past few years, this language become one of the most popular programming languages. This is because of the simplicity in the language syntax and semantics. It is one of a very few high-level languages which can be looked like a low-level language.
在过去的几年中,该语言成为最受欢迎的编程语言之一。 这是因为语言语法和语义简单。 它是极少数可以看起来像是低级语言的高级语言之一。
![Image for post](https://miro.medium.com/max/9999/1*IfZpd0s87z7xRuUQo01uLg.png)
Documentation Section:
文档部分:
It is an optional section used to write the comments regarding the program and the programmer. i.e., name of the programmer, date it is designed and so on.
这是一个可选部分,用于编写有关程序和程序员的注释。 例如,程序员的姓名,设计日期等。
The comments are written within the comment symbols /* — — — — — — — */
注释写在注释符号/ *中— — — — — — — * /
The code which is mentioned within the comment symbol is referred as non-executable code.
注释符号中提到的代码称为不可执行代码。
The compiler ignores it. The code will not have any effect on the program.
编译器将忽略它。 该代码对程序不会有任何影响。
Link section:
链接部分:
It is the section where we link up the system library header files to our current program. So that the system library function present in those files could be utilized flexibly in our program.
这是我们将系统库头文件链接到当前程序的部分。 这样,这些文件中存在的系统库功能就可以在我们的程序中灵活利用。
The files are linked by means of a pre-processor directive #include
通过预处理程序指令#include链接文件
Example: #include<stdio.h>
示例: #include <stdio.h>
Definition Section:
定义部分:
It is also an optional section used to define symbolic constants called macros. The nature of symbolic constant is that it cannot be varied or changed during the execution of the program. A symbolic constant is defined by means of a pre-processor directive #define
它也是用于定义称为宏的符号常量的可选部分。 符号常量的性质是在程序执行期间不能更改或更改它。 符号常量是通过预处理器指令#define定义的
Example: #define PI 3.1423
示例: #define PI 3.1423
Global Declaration Section:
全球宣言科:
It is also an optional section used to declare the global variable that can be accessed through out the program in any function. These are also referred as external variables. These variables should be declared outside all the functions
它也是一个可选部分,用于声明全局变量,该变量可以通过程序中的任何函数进行访问。 这些也称为外部变量。 这些变量应在所有函数之外声明
![Image for post](https://miro.medium.com/max/9999/1*Gd5gHxmwstTY3pl4EsttZg.png)
This sample has two functions,
该示例具有两个功能,
- main() : A special function which will execute first whenever we run a program. main():一个特殊的函数,它将在我们运行程序时首先执行。
- printf() : A library function from standard input output library(stdio.h) used to print the (“character, string, float, integer, octal and hexadecimal values”) onto the output screen. printf():来自标准输入输出库(stdio.h)的库函数,用于将(“字符,字符串,浮点数,整数,八进制和十六进制值”)打印到输出屏幕上。
Pre-processors directives: These will Pre-process the program file, which is to be handed over to the compiler for the compilation.
预处理程序指令:这些指令将对程序文件进行预处理,该程序文件将移交给编译器进行编译。
Begin with a # (hash), # is a direction to the preprocessor
以#(哈希)开头,#是指向预处理器的方向
Syntax: #include<header file> or #include “header file”
语法 :#include <头文件>或#include“头文件”
Now let’s get started.
现在开始吧。
Personally, I prefer Dev C++ compiler over Borland TurboC++ or any other compilers for that matter.
就个人而言,我更喜欢Dev C ++编译器而不是Borland TurboC ++或任何其他编译器。
Throughout this guide, we will be using “Dev C++” compiler.
在本指南中,我们将使用“ Dev C ++ ”编译器。
To save a C program press ctrl+s
要保存C程序,请按ctrl + s
To compile a C program press F9
要编译C程序,请按F9
To Run a compiled program press F10
要运行已编译的程序,请按F10键
To compile and run press F11
要编译并运行,请按F11
To create a new source file press ctrl+n
要创建新的源文件,请按ctrl + n
To get the C program output successfully it must pass through two environments.
要成功获取C程序输出,它必须经过两个环境。
1. Compile time environment
1.编译时环境
2. Runtime environment
2.运行时环境
During the compile time, it checks the syntax and Symantec errors and allocate memory for variables. During this time, it creates an object file with an extension .obj
在编译期间 ,它将检查语法和Symantec错误,并为变量分配内存。 在此期间,它将创建扩展名为.obj的目标文件。
During Run time, it performs computable instructions and input output statements etc. during this time, it creates an executable file with an extension .exe
在运行时 ,它执行可计算指令和输入输出语句等。在此期间,它创建一个扩展名为.exe的可执行文件。
The only way to learn a new programming language is, by writing programs in it. In C, the program to print Hello is
学习一种新的编程语言的唯一方法是通过用它编写程序。 在C语言中,打印Hello的程序是
![Image for post](https://miro.medium.com/max/9999/1*WiBW-6_Yf0MHw0jN7UkyBQ.png)
The first line of the program,
该程序的第一行,
#include<stdio.h> provides all the necessary functions for out program.
#include <stdio.h>为out程序提供所有必需的功能。
Normally, you are free o give function whatever name you like but main function is special. Every ‘C’ program begins execution from the main function. This means that every ‘C’ program must have a main function.
通常,您可以自由使用o随意给函数命名,但是main函数是特殊的。 每个“ C”程序都从主函数开始执行。 这意味着每个“ C”程序都必须具有主要功能。
Main will usually call other function to perform its job. User can call some user defined functions that you wrote and others from libraries provided. It is the best example of user defined function. It is not a system library function.
Main通常会调用其他函数来执行其工作。 用户可以从提供的库中调用您编写的某些用户定义函数,而其他函数则可以调用。 这是用户定义函数的最佳示例。 它不是系统库功能。
One method of communicating data between function is the calling function to provide a list of values. Known as arguments to the function. It passes the arguments to the called function by mentioning in the parenthesis. In this example, main is defined by a function that expects no arguments, indicated by ().
在函数之间传递数据的一种方法是调用函数以提供值列表。 称为函数的参数。 通过在括号中提及,将参数传递给被调用的函数。 在此示例中,main由不包含参数的函数定义,由()表示。
The statement of a function are enclosed in braces { }. The function main contains only one statement.
函数的语句括在大括号{}中。 函数main仅包含一个语句。
printf(“Hello”);
printf(“Hello”);
A function is called by naming it, followed by its arguments. So, this calls the function whose name is printf, with the argument “Hello”. Printf() is a library function that prints string of characters between the quotes. A sequence of characters in double quotes, like “Hello” is called as character string or string constant.
通过命名函数,然后命名参数来调用函数。 因此,这将使用参数“ Hello”调用名称为printf的函数。 Printf()是一个库函数,在引号之间打印字符串。 用双引号引起的字符序列(例如“ Hello”)被称为字符串或字符串常量。
The escape sequence \n in the string is ‘C’ notation for the new line character which when printed advances the output to the left margin on the next line. If you leave out the \n (try) you will find that there is no line advanced after the output is printed.
字符串中的转义序列\ n是换行符的'C'表示法,当打印时将输出前进到下一行的左边距。 如果省略\ n(尝试),则会发现在打印输出后没有前进的行。
Note: Suppose if you save a ‘C’ file it stores with an extension .c
注意:假设您保存的文件'C'以扩展名.c存储
In ‘C’ all variables must be declared before they are used at the beginning of the function and before by an executable statement. A declaration announces the properties of variables. It consists of a type name and a list of variables, such as
在“ C”中,必须先声明所有变量,然后才能在函数开始之前以及在可执行语句之前使用它们。 声明声明变量的属性。 它由类型名称和变量列表组成,例如
Int x,y,z;
整数x,y,z;
The type int means that the variables listed are integers. Similarly, the type float means floating point, ie., Numbers that may have a fraction part.
int类型表示列出的变量是整数。 同样,float类型表示浮点,即可能具有小数部分的数字。
![Image for post](https://miro.medium.com/max/9999/1*ugThJAmzbaRzOJ2RhaLx6g.png)
‘C’ provides several other basic data types besides int and float. Some of them are
除了int和float外,'C'还提供了其他几种基本数据类型。 他们之中有一些是
· Char Character — a single byte
·字符-单字节
· Short short integer
·短整数
· Long long integer
·long long整数
· Double double precision floating point
·双精度双精度浮点数
Variables and constants are the basic data objects manipulated in a program
变量和常量是程序中操作的基本数据对象
Declarations: List the variables to be used, and state what type they have and what their initial values are.
声明:列出要使用的变量,并声明它们的类型和初始值。
Operators: Specifies what to be done to them.
运算符:指定要对他们执行的操作。
Expressions: Combine variables and constants to produce new values
表达式:组合变量和常量以产生新值
That’s all for this story. In the next story I will go through some fundamentals in C. Thank You.
这就是这个故事的全部。 在下一个故事中,我将介绍C的一些基本知识。谢谢。
— Bharadwaj Yellapragada
— Bharadwaj Yellapragada
翻译自: https://medium.com/@saisrinivasabharadwaj/c-programming-chapter-1-introduction-797e22290f5f