Introduction Johnny.deng
1. C language is intermediate language:
C language is often referred to as an intermediate computer language. Intermediate languages are not derogatory, do not mean that it is poor, it is difficult to use,
Or the primary language like B A S i c, P a S c a l, nor means that it is similar to the assembly language, which will bring similar trouble to the user. The reason whose C language is called intermediate languages is because it combines the components of the advanced language with assembly language.
2. The basic components are compact and concise: only 32 standard keywords, 45 standard operators, and 9 control statements;
3. Data structure is rich in portability: Provide various data structures and control structures required to write structured procedures, and data related to hardware operations can be implemented by calling the library function provided by the system.
4. Language is structured language: Although from strict academic views, C language is block structure (it is often referred to as structured language. This is because it is similar to Algol, Pascal, and ModuLA-2 structures (technically, block structural language allows for defining a process or function in process and functions. With this method, global and local concepts can pass Domain rules extension, "Scope" management variables and "visibility" of the process. Because the C language does not allow function to define functions in the function, it is not possible to call the block structure language in the usual sense).
basic knowledge
I. Data type and arithmetic expression
1. The language has five basic data types: characters, integer, single precision real, double precision, and empty types. Although these
The length and range of type data is varied as the type of processor and the implementation of the C language compiler, but as an example of Bit, an integer
Equal with the CPU word length, one character is usually one byte, and the exact format of the floating point value is determined according to implementation.
2. The internal operator of the C language is very rich, and the operator is a symbol that tells the compiler to perform a specific arithmetic or logical operation. The C language has three operators: arithmetic, relationship and logic, bit operation. In addition, C is still some special operators for completing some special tasks.
3. Expression consists of operators, constants, and variables: C language expression basically follows general algebra rules.
two. Program control statement
1. Data input and output
During the operation of the program, it is often necessary to enter some data by the user, and the calculation results obtained by the program operation, etc., thereby realizing the interaction between the person and the computer, in the program design, input output statement Is an essential important statement, in the C language, there is no special input and output statement, all input and output operations are implemented by the call of the standard I / O library function. The most common input and output functions include scanf (), printf (), getechar (), and putchar ().
2. Condition control statement
In the three basic structures of the program, the second is the selection structure, its basic feature is: the process of the program is composed of multiple branches, and only one branch is selected according to the different cases, according to different conditions. Execute, while the statements on other branches are skipped directly. In the C language, the IF statement and the Switch statement selection structure are provided, and the IF statement is used for the case of choice, while Switch is used for multi-branch option.
3. Cyclic control statement
The loop control structure (also known as repetition structure) is another basic structure in the program. In practical problems, a large number of repetition processing often needs to make us only write little statements, and make the computer repeatedly, thereby completing a large class of calculations. The C language provides the WHILE statement, the DO ... While statement, and the for statement implementation loop structure.
Item. Function
When people solve a complex problem, it is usually used to gradually decompose, and the method of dividing it, that is, one
The big problem is broken down into a small problem that is relatively easy to solve, and then solve separately. Programmer design a complex application
When the program is often divided into a program module that is more than a single function, then achieved, most
Then all the program modules are arranged like a wood, which is a strategy that is cured in programming.
Modular programming method.
In the C language, the function is the basic components of the program, so it can be easily implemented using functions as program modules.
C language program. Using functions, not only the program is modular, but the program is simple and intuitive, it improves the easy-to-readability and maintainability of the program, but also uses some of the ordinary calculations or operations to be used in the program. To call up time, this can greatly reduce the programmer's code workload.
1. Number description and return value
When a function does not clearly describe the type, the C language compiler will automatically use the default type of this function, and the default type applies to a large part of the function. When necessary to return other types of data, it takes two steps: First, you must give functions to a clear type specifier; secondly, the description of the function type must be in the first call for it.
before. Only in this way, the C compiler can generate a correct code for the function returned to non-integer values.
2. Scope rules
"Scope of Language" is a set of determine whether a part of code is "visible" or can access another part of code and data.
the rule of. Each function in the C language is a separate code block. The code block of a function is hidden in the function,
You cannot be accessed by any statement in any other functions (other than adjusting its statement) (for example, jump with G O TO]
It is impossible to go to another function). The code constituting a function body is hidden in other parts of the program, it
Neither affect the other parts of the program and is not affected by other parts. In other words, since the two functions have different scopes,
Code data defined inside a function cannot interact with the code and data defined within another function.
All functions in the C language are in the same scope level. This means that a function is defined in another function.
Internally is impossible.
3. Call and parameters of functions
If a function is to use parameters, it must define a variable that accepts the parameter value. In general, there are two ways to pass parameters to functions. The first name is called "Call By Value), which is to copy the value of the parameters to the formal parameters of the function. Thus, any change in the form parameters in the function does not affect the variables used in the call.
The second method of passing the parameters to a function is "Call by Reference). This method is to put parameters
Address Copy to the formal parameters, in the function, this address is used to access the actual parameters used in the call. this means,
The change in form parameters will affect the variable used in the call. In addition to a few cases, the C language uses assignment calls to deliver parameters. This means that the value of the variable used in the call is generally unable to change.
Remember that the transferred function is only a replica of the parameter value. All variables that occur during the function within the function cannot affect the calls used.
[example]
Main ()
{
INT T = 10;
Printf ("% D% D", S Q R (T), T); / * SQR (T) is a function call, T is in real parameters * /
}
INT SQR (X) / * function definition, x is form parameters * /
INT X;
{
x = x * x;
Return (X);
}
In this example, the parameter value passed to the function SQR () is replicated to the form parameter x, when the assignment statement x = x * x is executed, only the local variable X is modified. The variable T for calling S Q R () is still maintained at 1 0.
execute program:
R u n
100 10
four. Array
Array is a collection consisting of several similar variables that can be used with these variables. The array is composed of a continuous storage unit, the minimum address corresponds to the first element of the array, and the highest address corresponds to the last element, and the array may be one dimension, or a multi-dimensional. The general explanation of one-dimensional array is as follows: type-specifier var_name [size];
In the C language, the array must be displayed so that the compiler is allocated to allocate memory space. In the above formula, the type indicator refers to the type of the franchise group, that is, the number of each element in the array, the total number of bytes of one-dimensional array can be pressed: sizeof (type) * array length = total byte number.
Obviously, the most common usage of a one-dimensional array is as a string. In the C language, the string is defined as a empty word.
The end of the character array. The empty character is identified with '/ 0', which is usually not displayed. Therefore, when the character array is explained,
Multiple characters must be more than one of the longest strings to be stored. For example, if you want to define a string that stores length 1 0
Array S can be written: char s [11];
This retains the space for the empty character at the end of the string. Although the C language does not define a string as a data type, it allows the usage of string. String constant is a character table enclosed by a double quotation. You don't have to add empty characters to the end of the string, the C compiler will automatically complete this.
C language supports multi-strill-operated functions, the most commonly used:
Name function
STRCPY (S1 S2) Copy S 2 to S 1
STRCAT (S1 S2) connects S 2 to the end of S 1
Strlen (S1) Returns the length of S 1
STRCMP (S1, S2) If S 1 is equal to S 2, the return value is 0
If S1 If S1> S2, the return value is greater than 0 [example] # include Main () { Char S1 [80], S2 [80]; / * Define the character number * / Gets (S1); / * Enter string * / Gets (S2); Printf ("Lengthsf:% D% D / N", S T R L E N (S 1), S T R L E N (S 2)); IF (! STRCMP (S1, S2)) Printf ("THE STRINGS Are Equal / N); S T R C A T (S 1, S 2); Printf ("% s / n", s 1); } I think that when two strings are equal, the function strcmp () will return false, so when the test string is equivalent, As in the example, the logical operator must be used! Take the test condition inverse. When the program runs and "Hello" and "Hello", the output is: Run Hello Hello Lengths: 5 5 THE STRINGS ARE Equal H E L o h E L L o Fives. pointer The pointer is the essence of the C language. By using the pointer, we can use memory resources well to make it the greatest. effectiveness. With pointer technology, we can describe complex data structures, which can be more flexible for the processing of strings, more convenient to process the array, making the program's writing simple, efficient, refreshing. However, because of the initiator, it is difficult to understand and palm. Holding, the knowledge of a certain computer hardware is required, this requires more training, multi-speed mobile hand, can in practice Master you as soon as possible and become C. If the address of the variable is stored in the memory-specific area, these addresses are stored, such variables are pointer variables, by referring to access to the pointed variables, is an "indirect access" of variables. 1. Pointer and array Variables are addressed in memory, and arrays also have addresses in memory. For arrays, the number of group names is the first address of array amplifier. The pointer variable is an address for storing the variable, which can point to variables, of course, can also store the address of the group of the first site or array element. 2. Pointer array All of this type of array stored all of the pointers, which are used to point to a variable to replace these variables in the program, increasing flexibility. Pointer array definition form: Type logo * array name [array length] Such as: char * STR [4]; 3. Pointer to point to pointers A pointer variable can point to integer variables, real variables, character type variables, of course, can also point to pointer type variables. When this pointer variable is used to point to the pointer type variable, we call the pointer variable to the pointer, which may feel a slight port, but the address you think of a pointer variable is to point to the pointer to this variable; The meaning of double pointers is easy to understand. 4. Parameters of the main function From the form of a function parameter, it contains an integer and a pointer array. The each of the arrays points to a string. The pointer to the received pointer array is received from the start of the command line, and the command is received first, and thereafter is the parameter. 5. The data structure associated with the pointer, such as a function pointer, an array pointer, and the like. six. Bit operation 1. Characteristic Unlike other languages, C language supports all bit operators. Because the design of C language is to replace assembly languages, it must support assembly language has the operational power. Bit operation is in the byte or word Bit (BIT) performs testing, setting or shift, whereby the byte or word is for the CHAR and INT data type in the C standard. of. Bit operations cannot be used for Float, Double, Long Double, Void, or other complex types. The following table gives a bit operation. Operator. The true value table of the AND, OR and NOT (1 complement) in the bit operation is equivalent to the logical operation equivalent, the only different It is a bit operation to operate in a position. 2. Operator 3. Application Bits are often used for device drivers, such as modem programs, disk file hypervisors, and printer drivers. This is because bit operations can be blocked from certain bits, such as parity blocks (parity blocks to ensure that other bits in the byte do not have an error, usually parity bit is the highest bit of the byte). Usually we can operate A N D as a means of closing bit, that is, the bit of one of two operands is 0, and the corresponding position is 0 in the result. For example, the following function reads a character from the modem port by calling the function read_mode (), and puts the parity position into 0. Seven. In addition The content points of C also include structures and common numerals and input, output, and file systems. Due to the limit, it is not summarized. Learning experience and experience First, the learning language of the programming language is in practice, and more hands are more brain. Second, the C and C will be referred to each other, and more learning will be more beneficial to the understanding of the programming. Third, find the solution to the problem: 1. Help the book 2. Help the help system 3. Help to the master of the world 4. Help online information 5. Use your own knowledge system and thinking ability to innovate. Fourth, first put forward a very interesting question when you start studying, such as 10,000 pellets in a cube in a free movement, collision, (and then you can in which "sticky"). Then how to do it, just sport, then one by one gradually understand. Of course, the problem must be stepped. I like this method.