2011年12月6日星期二

c language

Baike card

C language is a computer programming language. It has a high-level language features, but also has the characteristics of assembly language. It consists of the United States Institute of DMRitchie Bell launched in 1972. After 1978, C language has been ported to have large, medium, small and on a microcomputer. It can work as a system design language, writing system, application, or as an application language, writing does not rely on computer hardware applications. Its wide range of applications, with strong data processing ability, not just in software development, and various types of research are required to use the C language, for writing system software, three-dimensional, two-dimensional graphics and animation. Specific applications such as microcontrollers and embedded systems development.

directory

Getting Started with structural features characteristic historical merits of the order of computing structure structure structure, loop structure choice keywords modular structure of the program development environment, including new standard features in C99 relative to the changes in graphics programming c89 Based on TC's graphics.h WIN32 API and some other graphics library instance of the Chinese classic textbook class C programming language structure 1. A C language source code can be one or more source files. 2. Each source file can be composed of one or more functions. 3. Whether by a number of source files, and only one has a main function, that is the main function. 4. Source can have pre-order (including the include command, if command, pragma command), the pre-command should normally be placed on the top of the source file or source code. 5. Every note, every statement must end with a semicolon. However, pre-order, function heads and braces 6. Identifier, the keyword must be at least a space between to show interval. If you already have a clear spacers or not to add spaces to the interval. Features 1. C is a high-level language. It is the basic structure of the high-level language and low-level language statements and practicality combined. C language can be the same as the assembly language of bits, bytes and addresses to operate, and these three are the basic unit of work computers. 2. C is a structured language. Structure of language distinguishing feature is the separation of code and data, that the various parts of the program in addition to the necessary exchange of information independent of each other outside. This approach enables the program-level structured clear, easy to use, maintenance and debugging. C-language function is provided to the user, these functions can be easily invoked, and with a variety of loops, conditional statements control program flow, so that the procedures were fully structured. 3. C-language function is complete. With a wide variety of data types, and introduces the concept of a pointer, make the program more efficient. And calculation functions, logic functions are more powerful, can achieve the purpose of making the game. 4. C language application range. Suitable for a variety of operating systems such as Windows, DOS, UNIX, etc.; also applies to a variety of models. C language for writing hardware needed to operate the occasion, significantly better than other high-level language, there are some large-scale application software is written in C language. Characteristics of the pointer is a major feature of the C language, C language can be said better than other high-level language is an important reason. Because it has a pointer, can be close to the operation of the hardware, but not to protect the C pointer operations, but also brought with it a lot of insecurity. C + + has been improved in this area, while retaining a pointer operations while enhancing security, supported by some users, but because of these improvements increase the complexity of the language, but also for the other part of the criticism. Java will learn the C + + lessons, canceled pointer operations, but also abolished the C + + to improve some of the controversial areas in the safety and suitability of areas have achieved good results, but in itself explain the virtual machine to run, run less efficient than C + + / C. In general, C, C + +, java system is considered the same language, they occupy a long list of the top three uses. C language with a strong mathematical point of view is that stored procedures based on the principle (store program concept) of the hardware architecture of the soft abstract. Introduction For a beginner, Microsoft Visual C + + is a good software. Friendly interface, powerful debugging is also very convenient. This is Microsoft out of a C-language integrated development environment (IDE), are: VC + +6.0, VS2005. VS2008. VS2010 and so on, into Enterprise Edition and Student Edition. For the beginner VC + +6.0 is relatively easy to use, but its poor standards support may make people develop bad programming habits. In unix / linux operating system, to learn c language in general use vim / emacs to edit the source file, using gcc to compile the source file, using the make utility to manage the compilation process. Other compilers, such as CodeBlocks10.05 (cross-platform linux / windows open free to support up to 29 different items), dev-c + + (open source free), turbo, c-free5.0, codelite (open source free), eclipse (free open source Java-based extensible platform) ... the history of the ancestors of the C language is the language BCPL. In 1967, Martin Richards of Cambridge CPL language has been simplified, so have the BCPL (Basic Combined Pogramming Language) language. In 1970, the U.S. Bell Laboratories Ken Thompson. The BCPL language based design is very simple and very close to the hardware of the B language (BCPL to take the first letter). And he wrote the first language, with B a UNIX operating system. In 1972, Bell Labs DMRitchie American language in the B final design on the basis of a new language, he took BCPL's second letter as the name of the language, this is the C language. In order to promote the UNIX operating system, released in 1977, Dennis M. Ritchie machines that do not depend on the specific system of the C language compiler text 1978 by the American Telephone and Telegraph Company (AT & T) Bell Labs has just released the C language. At the same time by the BWKernighan and DMRitchie co-authored the famous Usually referred to as However, in the Often called ANSI C. The first edition of K & R is also in many languages ​​is not precise enough detail for pcc this thrown to the side. Finally, C used in the early project dominated by commercial and government contracts, it means a recognition of the formal standard is important. Thus (in the MD McIlroy's urging), ANSI in the summer of 1983, under the leadership of the CBEMA established X3J11 committee, the purpose is to generate a C standard. X3J11 in late 1989 they presented a report [ANSI 89], and later accepted as the ISO standard is ISO / IEC 9899-1990. In 1990, the International Organization for Standardization ISO (International Organization for Standards) received 89 ANSI C for the I SO C standard (ISO9899-1990). In 1994, ISO revised the standard C language. In 1995, ISO made some amendments to the C90, the In 1999, ISO has the C language standard be revised to retain the basic features of the original C language, based on the need for it should increase the number of features, especially for C + +, some of the features named ISO/IEC9899: 1999. 2001 and 2004, has conducted two technical amendments. The popular C language compiler system mostly based on ANSI C as the basis for development, but different versions of the C compiler system implementation language features and syntax rules are slightly different. Advantages of simple and compact, flexible C language keywords a total of only 32, nine kinds of control statements, written procedures for free-form, is case sensitive. The basic structure of the high-level language and low-level language statements and practicality combined. C language can be the same as the assembly language of bits, bytes and addresses to operate, and these three are the basic unit of work computers. Rich set of operators C language operator covers a very wide, a total of 34 kinds of operators. C language to parentheses, assignment, and so cast as operator handling. So that the C language type of operation is extremely rich, diverse types of expression. Flexible use of various operators can be achieved in other high-level language is difficult to achieve the operation. Rich data types C data types: integer, real, character, array types, pointer types, structure types, union types. Can be used to achieve a variety of complex data structures operations. And introduces the concept of pointers, making the program more efficient. In addition the C language with powerful graphics capabilities, support for multiple monitors and drives. And computing, logic and powerful. At the same time for different compilers have a range of C is a structured language structured language distinguishing feature is the separation of code and data, that the various parts of the program in addition to the necessary exchange of information independent of each other outside. This approach enables the program-level structured clear, easy to use, maintenance and debugging. C-language function is provided to the user, these functions can be easily invoked, and with a variety of loops, conditional statements control program flow, so that the procedures were fully structured. Syntax restrictions are less stringent, although the C programming language is a large degree of freedom strongly typed language, but it's syntax is more flexible, allowing the writers have a greater degree of freedom. Allow direct access to physical address, the hardware to operate because the C language allows direct access to physical address, you can operate directly on the hardware, so both have a high-level language features, but also has many low-level language features, to the same alignment as the assembly language , and the address byte to operate, and these three are the basic unit of work the computer can be used to write system software. Generate high-quality object code, program execution is generally efficient than assembler generates object code efficiency by 10 へ 20%. Application range, portability good C language has an outstanding advantage is suitable for a variety of operating systems such as DOS, UNIX, windows 98. windows NT; also applies to a variety of models. C language has a powerful graphics capability, portability, and have strong data processing ability, thus suitable for writing system software, three-dimensional, two-dimensional graphics and animation, it is also the numerical calculation of high-level language. Disadvantages 1. C language shortcomings mainly in data encapsulation, which is what makes C in data security, there is a big flaw, which is C and C + + is a major difference. 2. C language syntax restrictions less stringent constraints on the type of the variable is not strictly affect the security of the program, the array index bounds without inspection. From the application point of view, C language is more difficult to master than other high-level language. Computing the C language is very flexible operation, function rich, far more than other types of computing programming language. Expression in the more compact than other programming languages, such as self-imposed, self-less, comma operator and the three head to make the expression more simple operation, but beginners often feel this expression difficult to read, the key reason for this is Operators and operations in order not thoroughly understood incomplete. When the composition of a variety of computing arithmetic expression, an expression that occur when multiple operators, operator precedence and associativity rules is very important. During the study, as long as we have a reasonable classification, we find they have learned in mathematics, computing the difference between the points, remember that these operations are not difficult, some operators will bear in mind in understanding the post- mind, handy for future use, and some can not remember being given up, so remember to use again when later than. First explicit operator precedence in different categories, combination of right to left, the other is from left to right, it determines the order of operations at the same level operators. structural order order structure of the program structure design is the most simple, just follow the corresponding solution to the problem in order to write the statement on the line It's execution order is from top to bottom, in sequence. For example: a = 3, b = 5, are switching a, b values, like this exchange two cups of water, which we have to take to the third cup, if the third cup is c, then the correct procedure is: c = a; a = b; b = c; execution result is a = 5, b = c = 3 If you change the order, written as: a = b; c = a; b = c; the execution result into a = b = c = 5, can not achieve the intended purpose, beginners most likely to commit such a mistake. Order structure can be used independently complete a simple application form, common input, calculation, output Trilogy program is a sequence of structures, such as calculating area of ​​a circle, the program is a sequence of statements entered the circle radius r, compute s = 3.14159 * r * r,[url=http://www.beatsbydresale.org/][b]title=Beats By Dre Sale[/b][/url], the output area of ​​a circle s. However, in most cases, the order structure is as part of the process, and other structures together constitute a complex process, such as the branch structure of the compound statements, loops and other structures in the loop. Select the structure in order to solve the structure of the procedure, although the calculation, output and other issues, but can not make judgments and choose. For the judge should first issue will be re-selected using the selection structure. Select the structure of the implementation is based on certain conditions selected execution path, rather than in strict accordance with the physical order of the statement appears. Select the structure of the program design is the key to construct the appropriate conditions and analysis of program flow branches, depending on the application process to select the appropriate select statement. Choose the structure for the relationship with logic or comparison conditional calculations, the design of such programs often have to first draw the process flow chart, and then the program flow to write source code, so do the analysis and programming languages ​​separate make things simple, easy to understand. Program flow chart is based on analysis of problem-solving program execution flow chart drawn. The choice of several basic structure ① if (condition)
{body}
choose this option in the choice of the body structure can be a statement at this time statement. It has two branch path, first, when the condition is true, execution branches of the body, or choose to skip the body, then select the body is not performed. Such as: To calculate the absolute value of x, according to the absolute value of the definition, we know that when x> = 0, its absolute value unchanged, but x <0 is the absolute value of x when its anti-numbers, so the program segment: if (x <0) x =- x; ② if (condition)
{choose road 1}
else
{2}
choose this road is a typical choice of structure, if the condition is true, execute path 1, 2 or execution path, path 1 and path 2 can be one or several of the statements constituted. Such as: seeking ax ^ 2 + bx + c = 0 root
analysis: because when b ^ 2-4ac> = 0, the equation has two real roots, or (b ^ 2-4ac <0) has two two conjugate complex roots. The program segment is as follows:
int a, b, c, d, x, y;
printf (;);
scanf ((d <0)
{
printf (/ 2 * a;
x =- b + sqrt (d) / 2 * a;
printf (;
} ③ IF nested branch statement: The statement format is:
if (condition 1) {select path 1}
else if (condition 2) {select path 2}
else if (condition 3) {select path 3}
... ...
else if (condition n) {select path n}
else {select path n +1}
FOR nested, the statement format is: < br> for (initial value A; range A; step A)
{
for (initial value B; range B; step B)
{
loop
}
}
FOR nesting example: multiplication table
main ()
{
int a, b, c;
for (a = 1; a <= 9; a + +)
{
for (b = 1; b <= a; b + +)
{
c = b * a;
printf (b, a, c);
}
printf (After more than three re-nested, sentence structure becomes very complicated for the program are extremely inconvenient to read and understand, the proposed re-nested in less than 3, more than 3 weight can use the following statement. ④ switch switch statement: This statement is also multi-choice statement, in the end which an execution, depending on switch settings, that is, the value of the expression to match with the constant expressions that way,[url=http://www.uggoutletmallonline.com/][b]title=UGG Mall[/b][/url], it is different if ... else statement, and all its paths are side by side, the program is executed, starting from the first branch to find, if they match, then execute the block, the path followed by the implementation of Article 2, 3 ... ... block the path, until it encounters a break statement; If not, find the next a branch of the match. The statement in the application to pay special attention switches to set reasonable conditions and the rational application of the break statement.
loop structure can reduce the workload of writing source code repeat, repeat a certain algorithm is used to describe the problem, which is programming a computer to play the best talent in the program structure, C language offers four loops, ie goto loops, while loop, do while loop and for loop. Four kinds of loops can be used to address the same issue, in general, they can replace each other for, but generally do not promote the use of goto loop, because the order is often forced to change the program to run the program will bring unexpected error. Particular attention should be included in the body of the loop tends to the end of the statement (that is, the loop variable value changes), otherwise it may become an endless loop, which is a common beginner's mistake. Similarities and differences between three loops: the while and do ... while loop, the loop variable is initialized before the loop body should operate, and 1 for loop is generally carried out in the statement; while loops and for loops are the first to determine expression, after the loop body is executed, and do ... while loop is to determine the expression after the loop body is executed, that the do ... while loop is executed at least once, and while loops and for once could not perform. Also note that these three loops are out of the loop with a break statement, continue statement ends with this cycle, while the composition of the goto statement and if the cycle is to use break and continue statements can not be controlled. Order structure, branch structure and loop structure is not isolated from each other, can have a branch in the loop, the order structure, the branch can also be circular, sequential structure, in fact, no matter what kind of structure, we can treat them as a broad statement. In the actual programming process often combined these three structures in order to achieve a variety of algorithms to design appropriate procedures, but to the larger problem of programming, the program will tend to write long, multi structural repeat, resulting in poor readability, it is difficult understanding, to solve this problem is the C program designed to be modular structures. Modular structure of the C language program modular structure of the program implemented as a function, be a complex C program is divided into several modules, each module is written into a C function, then the main function calls the function and the function call function to achieve a large C programming question, so often say: C = main functions + subroutine program. Therefore, the definition of a function call, the return value, etc. In particular, pay attention to the understanding and application, and debugging to be consolidated through the machine. Judge statement (select structural) loop (loop structure) jump statement (loop structure: whether the cycle) if the statement: keyword is the word itself has been using the C language, can not use the word for other purposes. For example, keywords can be used as variable names, function names defined by the ANSI standard C language keywords of 32: auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if while static key role will be based on the type of keywords and keyword into the data flow control keywords are two categories of Class name class and the role of a data type keyword A. Basic Data Types (5) void : no return value or function declaration with no arguments, declare an untyped pointer, explicit drop operation result
char: character type data, integer data belonging to a
int: integer, the compiler usually specified machine word
float: single-precision floating-point data, are floating-point data of a
double: double-precision floating-point data, are floating-point data of a B. type modifier key ( 4) short: modified int, short integer data, can be omitted, modified int.
long: modified int, long integer data, can be omitted, modified int.
signed: modification of integer data, signed data type
unsigned: modified integer, unsigned data types C. complex type keywords (5) struct: struct declaration
union: union Statement
enum: enum declaration
typedef: Statement type alias
sizeof: get a specific type or types of variable size D. storage level keyword (6) auto: automatic variable is specified as, by the compiler automatically allocated and released. Usually allocated on the stack
static: specified as static variables, static variables in the distribution area, modification of function, specify the scope of the function inside the file
register: specified as a register variable, the proposed compiler variables stored in the register use, function parameter can be modified, the proposed compiler to pass through the register rather than stack parameters
extern: specify a corresponding variable for the external variables that indicate the variable or function defined in another file, suggesting that the compiler encounters The variables and functions in other modules to find its definition.
const: and volatile together, specified variable values ​​may be system or other processes / threads to change, forcing the compiler to obtain from memory each time the value of the variable flow control keywords 2 A. jump structure (4) return: used in the function body , return a specific value (or void value, that is, no return value)
continue: end the current cycle, start the next round cycle
break: out of the current loop or switch structure
goto: unconditional jump statement B . branch structure (5) if: conditional statements, do not put a semicolon after
else: the negative branch of conditional statements (if used in conjunction with)
switch: switch statements (multiple branch statements)
case: switch statement, branch tag
default: switch statement in the C. Loop structure (3) for: for loop structure, for (1; 2; 3) 4; the execution order of 1 -> 2 -> 4 -> 3 -> 2 ... cycle, One 2 cycle conditions. In the for loop process, the expression is evaluated once an expression 2 and expression 3 may be evaluated multiple times, it may not calculate the time. Loop may be executed multiple times, it may not perform an.
do: do loop structure, do 1 while (2); the execution order is 1 -> 2 -> 1 ... cycle, 2 cycle conditions
while: while loop structure, while (1 ) 2; the execution order of 1 -> 2 -> 1 ... cycle, 1 cycle conditions
above loop, the conditional expression is true when the cycle is to continue to cycle out of the loop if false. Development environment used C-language IDE (Integrated Development Environment) with Microsoft Visual C + +, Dev-C + +, Code:: Blocks, Borland C + +, Watcom C + +, Borland C + + Builder, GNU DJGPP C + +, Lccwin32 C Compiler 3.1, High C, Turbo C , C-Free, win-tc and so on. After the new standard in the ANSI standard, C language standard in a considerable period of time remain the same, even though C continues to improve. (In fact, NormativeAmendment1 in 1995, has developed a new version of the C language, but little known in this version.) Standard was experienced in the 1990s to improve, which is ISO9899: 1999 (1999 published). This version is commonly referred to C99. It is ANSI adopted in March 2000. Features included in the C99 compiler limit increase of, for example, each line of source code required to support at least to 4095 bytes, variable names required to support the function name to 63 bytes (extern required support to 31) pre-treatment increased. For example: macros take parameters # defineMacro (...) __VA_ARGS__ when using the macro parameter if you do not write macros with #, # # such a thing will expand to an empty string. (I used to go wrong) Support / / line comments (this feature is actually a lot in C89 compilers are already supported) added a new keyword restrict, inline, _Complex, _Imaginary, _Bool support long long, long double _Complex, float _Complex this type of support <::> <%%>%:%:%:, and so strange symbols instead support a variable-length array. The length of the array can use variables. When it declared type, use int a [*] this is written. However, taking into account the efficiency and implementation, this thing is not a new type. It can not be used in the global, or struct union which, if you use such a thing, goto statement is subject to restrictions. Not on the block variable declaration at the beginning, for advocating such a written statement for (int i = 0; i <100; + + i) That is, int i's statement on the inside, i only effective for inside. (VC failed to comply with this standard, i also effective in the for outside) when something needs a similar temporary structure constructed, we can use (type_name) {xx, xx, xx} This is a bit like C + + constructor to initialize a structure The time is now possible to write: struct {int a [3], b;} hehe [] = {[0]. a =, [1]. a = 2}; struct {int a, b, c, d; } hehe = {. a = 1,. c = 3,4,. b = 5} / / 3,4 yes right. c,. d assignment inside the string, u unicode-character hexadecimal floating-point support for the description of so many printf scanf format string supports ll / LL (VC6 in the use of I64) corresponding to the new long long type. Description of the internal floating-point data to support the new standard, this can be specified with # pragma compiler in addition to already have __line__ __file__ outside, but also support a __func__ can get current function name for the very few expressions, but also allows the compiler to device made for simplification modified /% on the negative definition of processing, such as the old standard in the -22 / 7 = -3, -22% 7 = -1 and now -22 / 7 = -4, -22% 7 = 6 to cancel the default does not write a function return type is int provisions allowing the definition of struct array to write the last to do [] do not specify the length of the description const const int i; will be treated as const int i; to handle the increased number of standard and modified head documents, such as the definition of define bool int in the standard length defined in the plural wide definition of the generic character of little taste of math function with floating point related . in more than a va_copy can be copied. .. The parameters. in more than a struct tmx expansion of struct tm has done a wide-character input and output on a long integer, and so do also support relative to the corresponding changes in c89 1. Increase in C99 restrict pointer for increased public and restrict pointer type modifier, it is the initial visit to the only way an object pointer, only with a pointer expression to restrict access to objects. restrict the function pointer to pointer variables, primarily used for, or point with malloc () function allocate the memory variables. restrict the data type does not change the program semantics. If a function pointer to restrict the definition of two variables, the compiler assumes that they point to two different objects, memcpy () function pointer is restrict a typical application example. C89 in the memcpy () function prototype is as follows: Code: void * memcpy (void * s1, const void * s2, size_tsize); If s1 and s2 point to the object overlap, its operation is undefined. memcpy () function can only be used for non-overlapping objects. C99, memcpy () function prototype is as follows: Code: void * memcpy (void * restrict s1, const void * restrict s2, size_t size); restrict modification through the use of variables s1 and s2, can ensure that they point to the different prototype the object. 2. inline (inline) inline function in addition to maintaining key structural and functional is defined, enables programmers to write efficient code. Each function call and return will consume considerable system resources, especially when the number of function calls in a lot of repeat loop when normal circumstances, when a function call occurs, the argument needs into the stack, all register memory needs to be saved. When the function returns, registers need to restore. If the function code in-line expansion, when the code is executed, these operations save and restore tourism activities will happen again, and the function call will greatly accelerate the pace of implementation. The online extension of the function will produce a longer code, so should only be inline for application performance has a significant influence function and the function of the length of the shorter 3. New data types _Bool value is 0 or 1. C99 added to define bool, true and false header macro folder , so that programmers can write compatible with both C and C + + applications. When writing new applications, you should use header file bool macro. _Complex And _Imaginary C99 complex types defined in the standard are as follows: float_Complex; float_Imaginary; double_Complex; double_Imaginary; long double_Complex; long double_Imaginary. Header file defines macros complex, and the imaginary, and extends them to _Complex and _Imaginary, so when writing new applications, you should use header files and the imaginary in complex macros. long long int C99 standard introduced a long long int (- (2e63 - 1) to 2e63 - 1) and unsigned long long int (0 - 2e64 - 1). long long int can support 64-bit integer length. 4. Enhancement of the array variable length arrays in C99, the programmer declare the array, the array dimension can be any valid integer expression determined only at run time, including to determine the value of the expression of these arrays on the called variable-length arrays, but only the local array can be of variable length. Variable length dimension of the array is constant during the lifetime of the array, that is, variable length arrays are not dynamic. You can only change the size of the array. You can use * to define the uncertain length of variable length arrays. The type of modifier array declaration in C99, if you need to use arrays as function arguments, you can declare the array using the static keyword in square brackets, which is equivalent to tell the compiler, the argument points to the array will contain at least the specified number of elements. You can also declare an array of square brackets use restrict, volatile, const keyword, but only for the function arguments. If you restrict, the initial pointer is the only way to access the object. If you use the const, pointer always point to the same array. No sense to use volatile. 5. Single-line comments marked the introduction of single-line comment 6. Spread code and statement 7. Preprocessor to modify a, a list of macro variables can take arguments in macro definitions using ellipsis (。..) said. Pre-determined internal identifier __VA_ARGS__ where variables will be replaced. Example: # define MySum (...) sum (__VA_ARGS__) statement MySum (k, m, n); will be converted to: sum (k, m, n); variables can also contain variables. Example: # define compare (compf ,。..) compf (__VA_ARGS__) which compare (strcmp, b, _Pragma operator introduces the C99 compiler directive is defined in the program another way: _Pragma operator. The following format: _Pragma (_Pragma Operator allows the compiler directives in macro substitution. c, internal compiler directive STDCFP_CONTRACT ON / OFF / DEFAULT if it is ON, hardware-based floating-point expressions are treated as independent units. The default value is defined tools. STDCFEVN_ACCESS ON / OFF / DEFAULT tell the compiler can access the floating-point environment. The default value is defined tools. STDC CX_LIMITED_RANGE ON / OFF / DEFAULT If the value is ON, the equivalent of telling the compiler that a program contains some complex formula is reliable. The default is OFF. d, the new operating system within the macro __STDC_HOSTED__ if there was 1 __STDC_VERSION__ 199991L or greater. For C version __STDC_IEC_599__ if support IEC 60559 floating-point operations, compared with 1 __STDC_IEC_599_COMPLEX__ support IEC 60599 if complex operations, compared with 1 __STDC_ISO_10646__ supported by the compiler for the description of ISO / IEC 10646 standard format for the year and month: yyymmmL 9 . Compound assignment C99, compound assignment, you can specify the array of object types, structure, or union expressions. When using the compound assignment, you should specify the type in brackets, followed by a brace enclosed initializer list; if the type is an array, you can not specify the size of the array. Constructed object is unnamed. Example: double * fp = (double []) {1.1,2.2, 3.3}; This statement is used to create a double pointer pointing to fp, the 3-pointer and the first element of the array elements. Established within the compound in the file assignment only valid for the lifetime of the program. Established within the compound in the module assignment is a local object, after exiting the module no longer exists. 10. Flexible array structure member C99, the last element of the structure allows the size of the array is unknown, which is called flexible array member, but the structure of the flexible array member must be preceded by at least one other member. Flexible array members to allow the structure contains an array of variable size. sizeof returns the size of this structure does not include flexible array of memory. Flexible array member contains the structure with malloc () function for dynamic allocation of memory, and memory allocation should be larger than the size of the structure to accommodate the expected size of the flexible array. 11. C99 designated initializer, this feature is often used for sparse arrays are useful for programmers. Designated initializer usually two ways: for the array, as well as for structures and unions. The format for the array: [index] = vol; Where, index that array subscript, vol said the initial value of the array elements. For example: int x [10] = {[0] = 10, [5] = 30}; which only x [0] and x [5] has been initialized. The format for the structure or union as: member-name (member name) of the structure of the specified initialization allows a simple way to specify the members of the structure is initialized. For example: struct example {int k, m, n;} object = {m = 10, n = 200}; which is not initialized k. Structural members of the order of initialization is no limit. 12. printf () and scanf () function to enhance C99 series of printf () and scanf () family of functions introduced to deal with long long int and unsigned long longint data type properties. type long long int format modifier is ll. In the printf () and scanf () function, ll for d, i, o, u and x format specifier. In addition, C99 also introduced hh modifier. When using the d, i, o, u and x format specifier, hh specifies the char type variables. ll and hh modifier can be used for n specifier. A and A format modifier used in the printf () function, the result will be output in hexadecimal floating point number. The following format: [-] 0xh, hhhhp + d modifier when using the A format, x and p must be capitalized. A and a format modifier can also be used in scanf () function, used to read floating point. Call printf () function, allows the% f specifier with l modifier before, that is% lf, but it does not work. 13. C99 C89 in the new standard library header files define macros assert () character processing error reporting definition and implementation related to floating definition and implementation point of duty limits support a variety of related functions setlocale () math library with support for a variety of non-defined Jump define local signal values ​​ support variable length argument list defines commonly used constants support file input and output statement support a variety of other string functions support the new system time function C99 header files and libraries to support the complex algorithms given floating-point status flags and other aspects of floating-point environment access define standard, portable set of integer type. Also support the processing function of the maximum width of the integer first in 1995 when the first revision of the introduction of a variety of operators used to define the corresponding macro support Boolean data type type. Define macros bool, so that compatible with C + + define standard, portable set of integer type. This file contains the definition in in general types of floating-point macro first amended in 1995, when first introduced, to support multi-byte and wide-byte function First Amendment in 1995, when first introduced, to support multi-byte wide and byte classification and function 14. __func__ predefined identifier __func__ the store for that function name, similar to a string assignment. 15. Other features of the changes to relax the restrictions limit the conversion of standard C99 C89 standard data block nesting 15 127 nesting conditional statements within the identifier 863 in the number of valid characters in the 3163 external identifiers in a valid character structure or the number of 631 members of the joint number 1271023 in the function call in the number of parameters 31127 int no longer support implicit rules remove the implicit declaration of function return value constraint C99, non-empty type of function must use the return statement with no return value. Expand the meaning of the integer type extensions type int16_t integer length integer precision 16-bit int_least16_t length of at least 16 int_fast32_t most stable integer type, the length of at least the largest 32-bit integer type uintmax_t intmax_t largest unsigned integer type of promotion rules of integer type improve the C89, the expression of type char, short int or int value can be promoted to int or unsigned int. C99 in each integer type has a level. For example: long long int level higher than the int, int level higher than the char, etc. In the expression, its level is lower than int or unsigned int can be replaced with any integer type to int or unsigned int. Is necessary to note that, c99's main () function must return an int value required to activate the program (usually the operating system) 0 indicates a normal launch and non-zero exception. Graphical programming based on TC's graphics.h Turbo C provides a very rich graphical functions, all the graphics function prototypes are in the graphics. H, this section describes the initialization of graphics mode, the establishment of an independent graphics program, basic graphics functions, graphics, window graphics and text mode output, and function. In addition, the use of graphics functions to ensure that the display graphics driver * BGI, while the Integrated Development Environment Options / Linker in Graphicslib voted on, the only way to ensure the correct use of graphics functions. Different graphics mode initialization of graphics display adapters have different resolutions. That is, the same display adapter, the different modes have different resolutions. Therefore, before drawing the screen, the display adapter type must be set to display a graphics mode, graphics mode is not set in before the computer screen as the default text mode (80, 25-line character mode), then all graphic functions are not working. Setting the screen to graphics mode, the initialization function can be used the following graphics: void far initgraph (int far * gdriver, int far * gmode, char * path); which gdriver and gmode respectively graphics driver and mode, path is the graphics driver the directory path. The graphics drivers, graphics mode of symbolic constants and the corresponding resolution of the table below. Turbo C graphics drivers by the publishers, the file extension. BGI. Depending on the graphics adapter has a different graphics driver. For example, EGA, VGA graphics adapter driver on call EGAVGA.BGI. Graphics driver model symbolic constants and values ​​━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ graphics drivers (gdriver) graphics mode (gmode) < br> ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ symbol color resolution
constant sign of the value constant value
━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━
CGA 1 CGAC0 0 C0 320 * 200
CGAC1 1 C1 320 * 200
CGAC2 2 C2 320 * 200
CGAC3 3 C3 320 * 200
CGAHI 4 2-color 640 * 200
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ < br> MCGA 2 MCGAC0 0 C0 320 * 200
MCGAC1 1 C1 320 * 200
MCGAC2 2 C2 320 * 200
MCGAC3 3 C3 320 * 200
MCGAMED 4 2-color 640 * 200
MCGAHI 5 2-color 640 * 480
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
EGA 3 EGALO 0 16 640 colors * 200
EGAHI 1 16-color 640 * 350
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
EGA64 4 EGA64LO 0 16-color 640 * 200
EGA64HI 1 4-color 640 * 350
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
EGAMON 5 EGAMONHI 0 2-color 640 * 350
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
IBM8514 6 IBM8514LO 0 256-color 640 * 480
IBM8514HI 1 256-color 1024 * 768
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
HERC 7 HERCMONOHI 0 2-color 720 * 348
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
ATT400 8 ATT400C0 0 C0 320 * 200
ATT400C1 1 C1 320 * 200
ATT400C2 2 C2 320 * 200
ATT400C3 3 C3 320 * 200
ATT400MED 4 2-color 320 * 200
ATT400HI 5 2 colors 320 * 200
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
VGA 9 VGALO 0 16-color 640 * 200
VGAMED 1 16-color 640 * 350
VGAHI 2 16-color 640 * 480
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
PC3270 10 PC3270HI 0 2-color 720 * 350
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
DETECT 0 for hardware testing
━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━ ━
use VGA graphics initialization function to set high resolution graphics mode # include
int main ()
{
int gdriver, gmode;
gdriver = VGA;
gmode = VGAHI;
initgraph (& gdriver, & gmode, closegraph ();
return 0;
}
sometimes the programmer does not know which type of graphics display adapter, or the need to write programs for different graphics drivers, Turbo C provides an automatic detection monitor the hardware function, the call format: void far detectgraph (int * gdriver, * gmode); which gdriver and gmode meaning the same as above. Automatic testing of graphical hardware initialization # include
int main ()
{
int gdriver, gmode;
detectgraph (& gdriver, & gmode); / * automatic test hardware * /
printf ((& gdriver, & gmode, , 1);
getch ();
closegraph ();
return 0;
}
the example of the graphical display program automatically detects the first, and then use the graphics initialization function initialization settings, but the Turbo C provides a more simple method, which uses driver = DETECT statement and then with initgraph () function on the line. Using this method, the above example can be changed to:
# include
int main ()
{
int gdriver = DETECT, gmode;
initgraph (& gdriver, & gmode , 0;
}
In addition, Turbo C graphics state provides a function to exit closegraph (), the call format: void far closegraph (void); exit after calling this function to enter text mode graphics state (Turbo C default), and release to save the graphics drivers and fonts of system memory. WIN32 API-based graphics library, and some other graphics library graphics.h fact TC2.0 limited functionality: 256 colors, 640 × 480 resolution, has become obsolete, so now basically no longer in use. WIN32 API with the C language to write a windows application. In fact, we have a better choice: MFC, QT, OpenGL, DirectX. One study MFC (Microsoft Foundation Class Library), QT need to know C + + can. It is proposed to learn about C + + and in-depth study and a library. Example feature: keyboard input polygon by the number of edges, find the angles and.
procedures are as follows:
# include
int main ()
{
/ * set up to identify whether the polygon is not set up to re-execute the statement between the do-while command * /
do
{
int x;
printf (value * /
printf (establishment, not to set up display n two numbers, the display shows a large number of
# include
int big (int, int); / * create integer variable functions big * /
int main () < br> {
int x, y;
scanf ((x, y));
/ * output the value of big function, because the main function with user-defined functions big no relationship, so printf output after the entry table is big (x, y), rather than big (n1 , n2) * /
getchar ();
return 0;
}
int big (int n1, int n2) / * User-defined functions big * /
{
if (n1> n2)
return n1; / * return n1 value * /
else
return n2; / * return n2 value * /
} function: the input from the keyboard of an isosceles triangle layer, draw a triangle like
# include
int main ()
{
int i, j, n;
printf (;);
scanf ({
for (j = 1; j <= ni; j + +) / * output the row in front of the space * /
printf (= 2 * i-1; j + +) / * output the row of asterisks * /
printf (> getchar ();
return 0;
} function: a maximum input from the keyboard, find the two to the maximum in all the prime numbers (prime) procedures are as follows:
# include ;
# include
void main ()
{
int n, m, flag, i, j, num = 1;
printf (= n; i + +) / * loop to find a prime number * /
{
flag = 1;
m = (int) sqrt (i);
for (j = 2; j <= m; j + +)
if (i% j == 0) / * condition is true that not a prime number, exit for loop * /
{
flag = 0;
break;
} < br> if (flag == 1) / * condition is true that i is a prime number * /
{
printf (output up to 10 numbers per line * /
{
printf (; n # include
# include
void main ()
{
int gdriver = DETECT; / * define the image drive to DETECT * /
int gmode = DETECT; / * define the image mode DETECT * /
long n; / * define the long variable n * /
initgraph (& gdriver, & gmode, bgi path, for example, the path is C: TC, it is to enter C: TC bgi) * /
sleep (1); / * pause a second, to ensure error-free into the image state * /
for (n = 1; n <= 40000000; n + +) / * draw 40 million round * /
{
setcolor (rand ()); / * random drawing color * /
circle (random ( 639), random (639), 25); / * draw a circle, random location, a radius of 25 * /
}
getchar ();
return 0;
} function: read a file, and hexadecimal display the following source code for the program:
/ * Program 12.6 Viewing the contents of a file * /
# include
# include ;
# include
# define DISPLAY 80
# define PAGE_LENGTH 20
int main (int argc, char * argv [])
{
char filename [80];
FILE * pfile;
unsigned char buffer [DISPLAY - 1];
int count = 0,
lines = 0,
i = 0;
if ( argc == 1)
{
printf (,],[
return -1;
}
while (! feof (pfile))
{
if (count buffer [count + +] = (unsigned char) fgetc (pfile);
else
{
for (count = 0; count printf (printf ('.');
printf (')
return 0;
}
}
for (i = 0; i if (i printf (02X ; i + +)
printf ();
pause ();
return 0;
} classic textbook Ritchie and the famous computer scientist Brian W. Kernighan co-author of an authoritative introduction to C language classics. Known as According to the original 1987 version 2 standard developed ANSIC made appropriate amendments, the introduction of a new form of language, and added a new example, through the simple description of a typical example, the authors comprehensively, systematically and accurately describes the C language features and programming all the basic method. For computer professionals, this book is a must-read programming language reference books.
book C, history, language features, statements, arrays, pointers, links, run-time, memory, and how to further learning C + + and other issues detailed explanations and in-depth analysis. The book captured a few examples to explain dozens of C programmers have a very high practical value. Starting point for writing this book is not to criticize the C language, but to help C programmers to bypass the process of programming pitfalls and obstacles.
book is divided into eight chapters, respectively, from the lexical analysis, semantic, connection, library functions, preprocessor, portability, and several other aspects of defect analysis of the C programming may encounter problems. Finally, the authors used a chapter gives some recommendations of practical value. Book through the basics of pointers and advanced features to explore, help programmers to the power of the pointer into the program to their own. The book is 18 chapters, covering the data, statements, operators and expressions, pointers, functions, arrays, strings, structures, and unions, etc. Almost all the important topics of C programming. The book gives a lot of programming tricks and tips, each chapter has highly targeted exercises, appendix shows the part of the exercise is the answer. The first section discusses the C language, all language features, including lexical, pretreatment system, declarations, types, expressions, statements, and functions such as basic language features. The second section discusses the C language standard library, according to their different functions are described in detail. To help the reader understand the concepts, the book in the C language and standard library to discuss all aspects of the issue, provides many examples and explanations. In the first part of each chapter also provides exercises, the book gives the main practice is the answer. The main purpose of these exercises is to help the reader understand the basic mechanism of the C language and its important details, which do not involve complex technical and programming issues. A total of 17 book chapters. Chapter 1.2 to learn C programming required prior knowledge. 3 to 15 of the C language-related knowledge, including data types, formatted input and output, operators, expressions, flow control statements, functions, arrays and pointers, string manipulation, memory management, bit manipulation, etc., knowledge of content standards for C99; In addition, Chapter 10 to strengthen the discussion of pointers, Chapter 12 introduces the concept of dynamic memory allocation, which is much more suited to the needs of readers. Chapter 16 and Chapter 17 discusses the C preprocessor and C library functions, advanced data representation (data structure) aspects. The appendix gives the back of each chapter review questions, answers and rich programming practice in C programming reference. C-like programming language, Chinese has launched for the Chinese people, Chinese C language, that is, c language, and O intermediate language. Learning Chinese language is pure C language, Turbo C 2.0 is all imitation, and is said to support all the TC2 function (actually not unknown). O and the intermediate language is so similar to the C language, but incomplete compatibility, in fact it is just laying the groundwork for the next O-language development. Open Category: Programming, Internet, technology, computer, high-level programming language to improve my Related articles:

没有评论:

发表评论