C语言中英文翻译资料.doc_第1页
C语言中英文翻译资料.doc_第2页
C语言中英文翻译资料.doc_第3页
C语言中英文翻译资料.doc_第4页
C语言中英文翻译资料.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 formed 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 performs 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 input/output facilities; there are no Read or Write statements, and no built-in file access methods. 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 information 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), formatted input and output, memory allocation, string manipulation, and the like. A collection of standard headers provides uniform 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 # define3 VALUE 6 int i, j ;main () j=1;for (i=1; i=VALUE; i+) j=j*I;printf (“The factorial of %d is %dn”, VALUE, j );As shown in the example, C code starts with # include , 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 float(for 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 main()function 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 format string and describes how the data is to be formatted when printed. The format 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 form of %d, which are used as placeholders for variables. The two operators(also called conversion specifications) in the format 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 format string corresponds exactly with the number and type of the variables following it. For example, if the format 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 integer(changing all references to lower-case because value is now a variable). Then place the following two lines at the beginning of the program:Printf (“Enter the value: ”);Scanf(“%d”, &value);Make the changes, then compile and run the program to make sure it works. Note that scanf uses the same sort of format string as printf. The & sign in front of value is the address operator in C, which returns the address of the variable. You must use the &operator in scanf on any variable of type char, int, or float, as well as record types. If you leave out the & operator, you will encounter an error when you run the program. 译文C语言C语言是一种高级程序设计语言,是20世纪70年代由Dennis Ritchie和Brian Kernighan在贝尔实验室开发的。虽然C语言最初是作为一种系统语言设计的,但后来的实践证明C语言功能强大,也十分灵活,可以用于各种应用程序,如商业软件、工程项目等,C语言在个人计算机编程领域非常流行,因为C语言规模较小比其他语言需求的内存少。用C语言编写的第一个重要程序是UNIX操作系统;以后多年之中,大家普遍认为C语言是与UNIX操作系统密不可分的。不过,现在C语言已经是一种与UNIX无关的重要语言,虽然C语言是一种高级语言,但是它比其他高级语言更接近于汇编语言。正是因为与低层的机器语言十分接近,C程序员才可以编写高效率的代码。不过,C语言的这种低级性在某些应用场合也显得难以驾驭。以下我们将从历史和技术的角度对C语言作一概括。作为一种通用的程序设计语言,C语言是在UNIX环境下开发出来的。UNIX系统本身及其应用程序也都是用C语言编写的,所以C语言一直与UNIX有着密切的关系。不过,C语言并不局限于某种操作系统或机型;C语言一直被称作一种“系统开发语言”,因为它在编写编译程序和操作系统方面特别有用,但是,在其他领域的大型程序开发方面也表现得同样出色。C语言的许多重要思想来自于Martin Richards研制的BCPL语言。BCPL语言对于C语言的影响是通过B语言间接地进行的。B语言是Ken Tompson于1970年为DECPDP7计算机上的UNIX系统而开发的。BCPL语言和B语言都是“无类型的”语言。相比之下,C语言提供了各种数据类型。其中基本的数据类型包括:字符型、整数型、各种精度的浮点型、数组型、结构型,及其联合体。表达式是由操作数组成的;任何的表达式,包括赋值及函数调用都可以作为一条语句。指针则可以提供与机器无关的地址运算。C语言提供了各种基本的流程控制结构,用于结构化程序设计。如:语句分组、判定结构(if-else)、情况结构(switch)、终止于顶部的循环结构(while,for)、终止于底部循环结构(do),及其循环中断命令(break)。函数的返回值可以是基本类型、结构、共同体或指针。任何的函数均可以递归调用。通常局部变量都是“自动型的”,或者说,是在每次调用时重新建立的。函数定义不能嵌套,但是变量可以在块结构中说明。C程序的函数单独存放于源文件中,分别编译。变量可定义为函数的内部变量,某一源文件中可以使用的外部变量,也可以定义为整个程序均可见的全程变量。预处理功能可以对程序文本进行宏替换,并可以蕴含其他源文件,或进行条件编译。C语言是一种相对低级的语言,也就是说它可以处理大多数机器本身所能处理的数据类型,如:字符、数值、地址等。这些数据既可以同机器所支持的算术和逻辑运算符组合,也可以由它们进行传送。对于字符串、集合、表、数组等组合数据类,C语言没有提供直接的操作。虽然一个结构可以整体复制,但是C语言中无法对整个数组或字符串进行整体操作。除了函数内的局部变量可以进行静态定义和堆堆栈无用内存收集机制。最后一点,C语言本身也没有提供输入/输出功能,没有读/写语句及内在的文件存取方法。所有这些高层的机制都是由通过函数显式调用的。大多数的C语言版本都带有基本标准的函数库,其中包含了以上这些函数。基于同样的道理,C语言仅仅提供了直接的、单线程的流程控制,如测试、循环、分支及子程序等;没有多道程序控制、并行操作、同步,协同例程管理。没有上述功能看起来像是一种缺陷,不过,把语言控制在较小的规模确有许多优点。鉴于C语言相对较小,可以用比较少的篇幅予以描述,并可以短时间内掌握。如果说程序员可以了解、掌握并确定经常使用全部的语言,并不奇怪。1983年,美国国家标准协会(ANSI)成立了一个专门的委员会,对C语言进行全面的、现代化的定义。其结果便是ANSIC,是1988下后期完成的,这一标准的大多数功能在较新的编译系统中业已付诸实施。这一标准是基于早期的C语言参考手册建立的,相对而言,语言本身没有多大变化;其目的之一就是为了保证现存的大多数程序可以有效运行,或者,在不兼容的情况下,由编译程序提出警告,说明(程序可能导致的)新的操作。对大多数程序员来说,最重要的变化是函数的说明及定义有了一种新的语法。现在,在函数的说明中可以包含参数的描述;函数的定义语法也作了相应的修改。有了这种附加信息,编译程序就可以很容易地检查出由于参数类型不匹配所造成的错误。事实证明,对C语言的这一扩充非常奏效。ANSI C对C语言的第二个贡献是定义了一套伴随C语言的函数库,其中说明的函数涉及到对操作系统的访问(如文件的读写)、格式输入输出、内存分配、字符串操作等等。ANSI C还规定了一套标准的首标文件,提供了对于函数说明及数据类型的统一使用方法。程序只要使用这一函数库与机器交换信息,其兼容性就可以得到保证,大多数的库函数都是以UNIX系统的“标准的I/O函数库”为基础建立的。虽然C语言可以充分发挥多数计算机的功能,但是,它并不依赖于具体的计算机体系结构,只需稍加注意,就可以编写出可移植的应用程序,也就是

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论