C Primer Plus (二)

Rereading C Primer Plus, you may say

  Rereading C Primer Plus, missing records, not the master, not clear knowledge

 

Branch and jump

  1, ctype.h header file contains functions for character determination column, including determining a number, uppercase and lowercase letters, control characters, can print a series mapping function and a character conversion function capitalization of characters and the like.

  2, C99 standard compilers support layer at least 127 nested if-else.

  3, comprising iso646.h header files, can be used and, or, not in place of &&, || ,! This is to accommodate the keyboard symbols around the world.

 

Character input / output and input validation

4, fully buffered into the buffer and the row buffer, the buffer is completely emptied when the buffer is full, the line buffer empty linefeed encountered, such as file input (complete) and standard input (OK), the buffer size depends on the operating system, 512 and 4096 bytes are common values.

5, in most Unix environment, with the [Ctrl + D] can generate a simulated signal end of the file, to read standard input notifications have been scanned and which may also be interactive mode and Python interact with this shortcutsClose For mode.

6, the redirection operators under Unix, input redirection <, output redirection>, two operators may be used in combination. They can be connected only executable files and data files, not the same type of connection, while the input and output can not be redirected to one or more files.

7, but Unix also has additional data operator >>, pipeline operator |, we must refer to the specific use of Unix-related books, and this is not part of the C.

 

function

8, pay attention to set recursive end condition, and a pointer usage, the rest does not need to pay attention.

 

Arrays and pointers 

  9, C99 standard initialization support a specific project, such as:

1 int arr[10] = {1,2,3,[5]=31}

Uninitialized project will be set to zero.

10, for a two-dimensional (multi-dimensional) array arr [n] [m] in terms of, arr + 1 and arr [0] +1 are different.

11, for two-dimensional arrays, the address the ARR, the value can be obtained extracted twice normal values.

1  here add an aside, the "C Primer Plus" fifth edition, P267 program code and the code in Listing 10.15 outputs
 2  results are inconsistent, two-dimensional array subscript written backwards.
3  in the output:
 . 4 Zippo [ . 1 ] [ 2 ] should be written Zippo [ 2 ] [ . 1 ]
 . 5 * (* (Zippo + . 1 ) + 2 ) should be written as * (* (Zippo + 2 ) + . 1 )

12, int (* arr) [2] represents a pointer to an array comprising two int;

int * arr [2] represents an array comprising two int type pointer, this difference occurs because the binding operator.

arr [m] [n] is equivalent to * (* (arr + m) + n)

13, for N-dimensional array, int arr [] [10] [20] [30] equivalent to int (* ar) [10] [20] [30]

The first square brackets can not write, because it is considered to be a pointer to an array of behind the digits that identify specific types of data, must be completed.

14, C99 standard supports variable length arrays, refers to an array variable dimension may be declared, not variable dimension, when the variable parameter in the function name is omitted, the dimension instead of applying the asterisk, int sum (int, int, int [*] [*]);

15, C99 standards support combined text, for example, (int [2]) = {10, 20}, because the variable is anonymous, it must be used immediately when the declaration or stored its address pointer. This feature is currently not used.

 

Strings and string functions

16, initialization string with a method to an array of tail all unused memory is initialized to \ 0, not only at the end of the string is assigned \ 0.

17, char * m3 = "hello" and char m3 [] = "hello" in almost the same action statement. The difference is that the array name is a constant, its value can not be modified, but the pointer is possible.

1  where discovered an error book:
 2 positions at the center-P285   const  char * M3 [] = " .... ..... omitted " be
 . 3                     const  char * M3 = " .... omission ..... "

18, for char arr [m] [n] and char * arr [], the former is a string array, the array is a rectangle, which is a string type of pointer array, it is actually rectangular, address is stored therein, and the string to a program stored in the constant storing portion, so that space is not wasted, but the strings can not be modified.

19, fgets function compared gets safer, you can specify the length of read data, newline also read, and can specify which reads a file, the UNIX standard input may be specified as stdin.

20, for the command-line parameters, the default operating system to divide a space string, UNIX also allows the use of a plurality of marks to the words in one parameter, the Example:

1 repeat "I am hungry" now

21, the string is converted to an integer, commonly atoi, there atof, atol. The complex has, strtol, strtoul, strtod, you can find the first non-numeric characters, and can be converted to the corresponding hexadecimal, not commonly used.

 

Storage class, links, and memory management

22, for a variable (known as a global variable) file-scope, static show the type of dimension that links internal links, only function in this file can access this variable.

23 or five storage class:

Storage Class period Scope Link Properties Declaratively
automatic automatic Block air Within a block of code
register automatic Block air Inner code block, using the keyword register
Static with external linkage Static state file Outside Outside of any function
Static has internal links Static state file internal Outside of any function, use the keyword static
Static air links Static state Block air The code block, the static keyword

 

24, for the following code:

1 double *ptd = (double*) malloc (30 * sizeof(double))

  In C, the type of assignment (double *) are optional, but must be in C ++, the use of the type of assignment allows porting of C to C ++ easier.

25, when allocating memory, calloc function receives two parameters, and will apply to all of the memory block is set to 0, but some hardware system is represented by floating-point values ​​are not all zero.

26, one in front const * becomes constant so that the data points, the const * so that the pointer is located to become constant.

27, restrict only be used to modify the pointer, and the pointer to the original data block and only accessed by the pointer, the compiler will According to this, the pointer of the operation involving a plurality of optimization.

28, in the C99 standard, there are some old keywords can appear in a new location.

1 void fun(int a1[const], int a2[restrict], int n)
2 void fun(double ar[static 20])

Guess you like

Origin www.cnblogs.com/Dylan7/p/12154459.html