c语言规范标准中英文,C语言中英文翻译资料.doc

253b171540df25e1b84436cbe50dfc72.gifC语言中英文翻译资料.doc

The C Programming LanguageC is a high-level programming language developed by Dennis Ritchie and Brian Kernighan at Bell Labs in the mid-1970s. Although originally designed as a systems programming language, C has proved to be a powerful and flexible language that can be used for a variety of applications, from business programs to engineering. C is a particularly popular language for personal computer programmers because it is relatively small-it requires less memory than other languages.The first major program written in C was the UNIX operating system; and for many years, C was considered to be inextricably linked with UNIX. Now, however, C is am important language independent of UNIX. Although it is a high-level languages, C is much closer to assembly language than are most other high-level languages. This closeness to the underlying machine language allows C programmers to write very efficient code. The how-level nature of C, however, can make the language difficult to use for some types of applications.Now lets take an overview of the C programming language, both historically and technically and technically.As a general-purpose programming language, C has been closely associated with UNIX system where it was developed, since both the system and most of the applications that run on it are written in C. The language , however, is not tied to any one operating system or machine; and although it has been called a “system programming language” because it is useful for writing compilers and operating systems, it has been used equally well to write major programs in various fields.Many of the important ideas stem from the language BCPL, developed by Martin Richards. The influence of BCPL on C proceeded indirectly through the language B, which was written by Ken Tompson in 1970 for the first UNIX system on the DEC-PDP-7.BCPL and B are “typeless” languages. By contrast, C provides a variety of data types. The fundamental types are characters, and integers and floating point numbers of several sizes. Additionally, there is a hierarchy of derived data types created with pointers, arrays, structures, and unions. Expressions are ed from operands; any expression, including an assignment or a function call, can be a statement. Pointers provide for machine-independent address arithmetic. C provides the fundamental control-flow constructions required for well-structured programs statement grouping, decision making if-else , selecting one of a set of possible cases switch, looping with the termination test at the top while, for or at the bottom do, and early loop exit break.Functions may return values of basic type, structures, unions, or pointers. Any function may be called recursively. Local variables are typically “automatic”, or created anew with each invocation. Function definitions may not be nested but variables may be declared in a block-structured fashion. The functions of a C program may exist in separate source files that are compiled individually. Variables may be internal to a function, external but known only within a single source files, or visible to the entire program.A preprocessing step pers macro substitution on program text, inclusion of other source file, and conditional compilation. C is a relatively low-level language, meaning that C deals with the same sort of objects that most computers do, namely characters, numbers, and addresses. These may be combined and moved about with the arithmetic and logical operators implemented by real machines.C provides no operations to deal directly with composeite objects such as character strings, sets, lists, or arrays. There are no operations that manipulate an entire any storage allocation facility other than static definition and the stack discipline provided by the local variables of functions; there are no heap or garbage collection . Finally, C itself provides no /output facilities; there are no Read or Write statements, and no built-in file access s. All of these higher-level mechanisms must be provided by explicitly-called functions. Most C implementations have included a reasonably standard collection of such functions.Similarly, C offers only straightforward, single-thread control flow tests, loops, grouping, and subprograms, but not multiprogramming, parallel operations, synchronization, or co-routines.Although the absence of some of these features may seem like a grave deficiency, keeping the language down to modest size has real benefits. Since C is relatively small, it can be described in a small space, and learned quickly. A programmer can reasonably expect to know and understand and indeed regularly use the entire language.In 1983, the American National Standard Institute ANSI established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or “ANSI C”, was completed late in 1988. Most of the features of the standard are already supported by modern compilers . The standard is based on the original C reference manual. The language is relatively little changed; one of the goals of the standard was to make sure that most existing programs would remain valid, or, failing that, that compilers could produce warning of new behavior.For most programmers, the most important change is a new syntax for declaring and defining functions. A function declaration can now include a description of the arguments of the function; the definition syntax changes to match. This extra ination makes it much easier for compiler to detect errors caused by mismatched arguments. This has proved to be a very useful addition to the language.A second significant contribution of the standard is the definition of a library to accompany C. It specifies functions for accessing the operating system for example, to read and write file, atted and output, memory allocation, string manipulation, and the like. A collection of standard headers provides uni access to declarations of functions and data types. Programs that use this library is closely modeled on the “standard I/O library” of the UNIX system.Although C matches the capability of many computers, it is independent of any particular machine architecture. With a little care it is easy to write portable programs, that is, programs that can be run without change on a variety of hardware.C, however, like any other language, has its blemishes. Some of the operators have the wrong precedence; some parts of the syntax could be better. Nonetheless, C has proved to be an extremely effective and expressive language for a wide variety of programming applications.Having reviewed the history and features of C, lets now study an example C program for a basic understanding of what a C program looks like. The following program finds the factorial of the number 6./* Program to find factorial of 6 */ include stdio.h define3 VALUE 6 int i, j ;main j1;for i1; iVALUE; i jj*I;printf “The factorial of d is dn”, VALUE, j ;As shown in the example, C code starts with include stdio.h , which instructs the compiler to include the standard I/O library into your program so that you can read and write values, handle text files, and so on. C has a large number of standard libraries like stdio, including string, time and math libraries.The define line creates a constant. Two global variables are declared using the int i, j; line, which announces the properties in this case, integer of the two variables. Other common variable types are floatfor real number and char for characters, both of which you can declare in the same way as int.The line main declares the main function. Every C program must have a function named main somewhere in the code, which marks the beginning of your program. In C, the statements of a function are enclosed in braces. In the example the mainfunction contains only three statement, which are an assignment statement, a for statement, and a printf statement.The printf statement in C is easier to use. The portion in double quotes is called the at string and describes how the data is to be atted when printed. The at string contains string literals or string constant such as The factorial of, n also called escape sequence. /n stands for carriage returns, and operators in the of d, which are used as placeholders for variables. The two operatorsalso called conversion specifications in the at string indicate that integer values found later in the parameter list are to be placed into the string at these points. Other operators include f for floating point values, c for characters, and s for strings.In the printf statement, it is extremely important that the number of operators in the at string corresponds exactly with the number and type of the variables following it. For example, if the at string contains three operators and it must be followed by exactly three parameters, and they must have the same types in the same order as those specified by the operators.This program is good, but it would be better if it reads in the value instead of using a constant. Edit the file, remove the VALUE constant, and declare a variable value instead as a global integerchanging all references to lower-case because value is now a variable. Then place the following two lines at the beginning of the programPrintf “Enter the value ”;Scanf“d”, Make the changes, then compile and run the program to make sure it works. Note that scanf uses the same sort of at string as printf. The main j1;for I1;IVALUE;I jj*I;printf“The factorial of d is d n”,VALUE,j;如例中所示,C语言程序(代码)以“includestdio.h”一句开始,其目的只是编译程序将C标准函数库蕴含到用户程序中,以便于读写数据、处理文本文件等等。C语言带有大量像“stdio.h”这样的标准函数库,包括字符串处理、时间及数学运算等函数库。“define”一行定义了一个常量。“int i,j”一行说明了两个全局变量,定义了两个变量的属性(本例中为整数)。其他常用的变量类型还有浮点型(指实数型)、字符型(指字符)等,其说明格式同整型类似。“main”一行说明了本程序的主函数。每一个C语言程序都必须有一个名为“main”的函数,可出现于程序的任意位置,用以标记程序的开始。在C语言中函数的语句都被括在一对中。在本例中,主函数包括三行语句,分别是赋值语句、for循环语句,及printf格式输出语句。C语言中的“printf”语句很容易使用。双引号中的部分叫作格式串,用于描述数据在输出时的格式。格式串可以包括字符常量,如“The factorial of”及“n”(又称作转义序列,n表示回车);还可以包括形如“d”的操作符,用作待输出变量的定位符。本例中格式串的两个操作符(又叫作转换说明),表示出现于后续参数表中的整型数值将被置于该格式字符串的指定位置。类似的格式操作符还有表示浮点数值的“f”、表示字符的“c”,及表示字符串的“s”等。必须注意,在“printf”语句中,格式串中操作符的数目与后续的变量在类型及数目上要严格对应。例如,如果格式串包含三个操作符,在后面的参数也必须有三个,并且参数在类型及出现的顺序上要与前面的操作符一致。这个程序还可以,不过,如果能将常量改为由程序读入数值,则会更好一些。编辑该程序,删除VALUE常量,并说明一个全局变量“value”(把所有变更引用都改为小写,因为“value”现已说明为一个变量),然后将以下两行加到程序的开始处printf“Enter the value”;scanf“d”,修改程序,进行编译并运行,以确保程序无误。值得注意的是,“printf”使用的格式串与“scanf”相同,“value”变量前的“”字符在C语言中称作地址操作符,用于返回指定变量的内存地址。出现于“scanf”中的字符型、整型、浮点型,以及记录型(即结构型)的任何变量都必须加上“”操作符。倘若漏掉“”,运行程序时就会出现错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值