Summary of "C and pointers"

Source: Internet
Author: User
Tags define definition define null strcmp strtok

Link Properties
1.extern 关键字用于标识符第二次或以后的声明并不会改变第一次声明所指定的属性。2.static 防止被访问 (和java完全不同)
Storage type
1.变量存储地方:普通内存,堆栈,硬件寄存器2.代码块外声明的是静态变量,存于静态内存(普通内存),程序运行前存在,始终存在3.自动变量4.代码块内变量 + static --> 静态变量
Operator
1. i+++ ++i 这种5个加号的存在,gcc中间有空格可以通过,甚至可以是6个,i+++ + ++i,一个表示正数
Pointer
1.定义:    #define NULL (void*) 0    #define EOF -12. int *a; *a=1;    unix:段违例 segmentation violation ,内存错误:memory fault,总线错误:bus error3.对NULL指针间接访问,有的编译器访问内存0,有的引发一个错误并终止程序4.尽量显示初始化指针5.指针与整型值的相互转换罕见6.*100=25  不是对100内存地址的地方赋值25,是非法的,100是整型, *(int *)100=25;    访问硬件本身,很少用7. * 从右向左的结合性8.后缀 ++ -- 顺序点   ()不是顺序点!     ;  ,  ||  &&  ?:  还有函数的所有的赋值之后,第一条语句执行之前。     函数返回值已拷贝给调用者但在该函数外代码执行之前     每个基类和成员初始化之后9. *cp++  *++cp  ++*cp  (*cp)++ ++*++cp  ++*cp++  *(*cp)++  后缀++优先级大于*   *不是++顺序点10.for(cp=&arr[0];cp<&arr[LEN];) *cp++;    for(cp=&arr[LEN];cp>&arr[0];) *--cp;    for(cp=&arr[LEN-1];cp>=&arr[0];cp--) *cp;//都是作为左值操作    第三句cp到达&arr[0]之后还减1,再进行比较 cp>=&arr[0]值是未定义的,因为cp移动到了数组边界之外    标准允许数组元素的指针与指向数组最后一个元素后面的那个内存进行比较,但不允许与数组第一个元素之前!11.指针的加减法会根据类型自动调整
Function
1.函数原型:向编译器提供一些关于函数的特定信息,更为安全2.函数原型参数不是必须3.没有参数的原型 int *func(void); void提示没有参数,而不是表示一个void类型的参数4.函数的缺省认定:程序调用一个无法见到原型的函数是,编译器认为该函数返回整型值5.stdarg 宏    定义在stdarg.h中,这个文件声明了一个类型 va_list和三个宏 va_start va_arg va_end    float average(int values,...){        va_list args;        int sum=0;        va_start(args,values);//准备访问可变参数        for(int count=0;count<values;count++){            sum+=va_arg(args,int);//访问可变参数        }        va_end(args);//完成处理可变参数        return sum/values;    }    参数列表至少有一个参数,否则无法va_start    无法知道实际参数长度,无法判断参数类型
Array
1. The array name is a pointer constant, not a pointer variable, and the compiler remembers the array property with the array name 2. After the program completes the link, the position of the array in memory is fixed and cannot be moved, so the array name is the pointer constant 3. Two cases where the array name is not represented by a pointer constant: 1) Operand as sizeof: Returns the entire array length of 2) as the operand of the single-Mesh operator &: Takes an address of an array name to return a pointer to an array instead of a pointer to a pointer constant!!  4.array[subscript] is equivalent to * (array+ (subscript)) subscript can even be negative 2[array]=* (2+array) =array[2] No difference to compilers 5. Subscripts are never more efficient than pointers, but pointers are sometimes more efficient than subscripts int array[10] A; for (a=0;a<10;a++) array[a]=0;//each time there will be a*4 int array[10] *AP;    for (ap=array;ap<array+10;ap++) *ap=0;//each time is the 1*4 pointer more efficient premise is the correct use, otherwise easier to write poor code! Some places are more difficult to maintain, some places to pursue peak efficiency 6. Declare the array parameter int strlen (char *string);//More accurate, because the argument is actually a pointer instead of an array int strlen (char string[]); 7. Static memory arrays are initialized only Once, before the program starts, by the linker, not explicitly initialized initializes 0 for automatic variables, the memory location is not deterministic, the default is uninitialized. Measure the pros and cons of adding Static8.char message[]= "Hello"; just char message[]={' h ', ' e ', ' l ', ' l ', ' o '}, another notation char *message1= "Hello"; is the real string constant initialization 9. In C, the order of multidimensional array storage is the principle of first change of the rightmost subscript, and becomes the row main sequence row major order10. int (*p) [10];//declaration pointer int matrix[3][10];P =matrix;//p point to matrix the first row 11. Avoid int (*p) []=matrix; this declaration. When a pointer operation is performed, its value is adjusted according to the length of the empty array, which is 0 multiplied by 12. Multidimensional arrays as function parameters need to know the second dimension and the subsequent dimensionsThe length, which must declare void func (int (*p) [x]), void func (int p[][]), is written as void func (**p); 13. pointer array int *P[10] The following table has higher precedence, is an array, 10 elements, element type refers to A pointer to an integer of 14.sizeof returns a value of unsigned int, the array as its parameter does not degenerate, returning the entire array occupies byte 15. Pointer array the last element is initialized to NULL for easy operation
strings, characters, and bytes
1. Contains the string.h, it contains the prototype can be a compiler to perform a better error detection 2. Write the string function yourself, preserving the function name starting with STR for extension 3 of the standard library.  size_t strlen (char const *string) size_t defined in Stddef.h, is a unsigned int program protection does not overflow 4. Unsigned number in an expression can lead to unpredictable results if (strlen (x)    >= strlen (y)) .... if (strlen (x)-strlen (y) >= 0) ....    Seemingly equal, in fact the second inning is always true, and the unsigned number cannot be negative 5. The standard library functions are the 6.char *strcpy (char *dst,char const *SRC) implemented by the assembler; SRC and DST overlap and the result is undefined if SRC is longer than DST, the extra characters will still be copied!    The 7.char *strcat (char *dst,char const *SRC) must be programmed;    SRC and DST overlap, and as a result undefined and strcpy, the remaining space must be guaranteed to be greater than src8.int strcmp (char const *s1,char const *S2);  S1 less than S2, returns a number less than 0, greater than the number returned greater than 0, equal to return 0 unequal if (strcmp (A, b)) 9.char *strncpy (char *dst,char const *src,size_t len);  Char *strncat (char *dst,char const *src,size_t len);  Char *strncmp (char const *dst,char const *src,size_t len); strncpy always copies the length to Len, if strlen (SRC) is less than len,dst with extra nul bytes filled to Len length if it is greater than Len, only len length is copied, but!  His results will not end with NUL!   Unlike strncpy, Strncat always adds nul to the result string, does not make a nul fill, and the maximum copy len length plus a nul, regardless of the space enough 10.char *STRCHR (char const *str,int CH); Char *strrchr (char consT *str,int ch);    STRCHR finds the position where CH first appears, returns a pointer to it, STRRCHR returns the last 11.char *strpbrk (char const *str,char const *group); Returns a character position of 12.char *strstr (char const *s1,char const *S2) that points to any character in the first matching group in STR; 13.size_t strspn (char const *STR,CHAR    const *group);//no longer within Group size_t strcspn (char const *str,char const *group); 14.char *strtok (char *str,char const *SEQ); Find the next character that consists of a SEQ set to split Str's token and end it with NUL, and return a pointer to this tag without the Const modifier STR, which will be modified and will be repeatedly called, known to return nul static char whitespace[]= "\t\f\r    \v\n ";//There is a space char *token; For (Token=strtok (line,whitespace); Token!=null;token=strtok (null,whitespace)) You can use a different SEQ each time you call Strtok,    The different parts of the string save the local state information of the function with different partition strtok, cannot parse multiple strings at the same time, call internal call in the For loop body, strtok function will cause the program to fail 15.char *strerror (int error_number) When calling a function or requesting an operating system function, such as an error in opening a file, the operating system is errno by setting up and returning an external integer variable, which accepts errors and returns a description 16. Character Classification: Ctype.h accepts a character's ASCII code, and the function tests the character, and return the shaping value to represent true or false Iscntrl isspace isdigit isxdigit islower isupper isalpha isalnum first three collection ispunct punctuation isgraph graphic character Isprint graphic word Characters and Spaces 17. Character conversion: Ctype.h int TolowER (int ch) int toupper (int ch) 18. Direct test or test will reduce portability if (ch>= ' A ' | | ch<= ' Z ') on the ASCII character set machine can but use the EBCDIC character set of the machine can not, if (Isupper (CH)) can! 19. Memory Operation: Resolves the string-to-end issue with length as the operation termination flag. void pointers, other data types can also use void *memcpy (void *dst,void const *src,size_t length) void *memmove (void *dst,void const *src,size _t length) compared to MEMCPY,DST and SRC can overlap, it takes advantage of a temporary space copy, slow void *memcmp (void const *a,void Const *b,size_t length) based on unsigned bytes For comparison, if the comparison is not single-byte data, the result is not measurable void *memchr (void *a,int ch,size_t length) void *memset (void *a,int ch,size_t length) from a start setting L Ength CH Length is the number of bytes of the operation, not one byte of the data type to be multiplied by length, such as the INT structure
Structural body
1.struct{....}x;struct{....}*y;这两个声明被编译器当成不同的声明,y=&x也是非法的,即使成员列表相同2.想在多个源文件中使用定义的结构体,放在头文件中3.间接访问运算符*的优先级小于成员访问 .     ->大于&4.可以包含自身的引用,但不能在没定义别名前用别名。不能包含自身,因为递归不能终止5.相互引用用不完整声明6.如果不存在将相关成员放在一起的要求,应该根据边界进行重排结构体的成员存储结构7.sizeof返回结构体的整体长度,offsetof宏(stddef.h)返回指定成员开始存储的位置距离结构体开始    存储的位置偏移几个字节,返回size_t,offset(type,member)type是结构名,member是成员名8.位段:    只能声明为int,signed int,unsigned int(用作表达式时自动升级的类型),    用int并不好,它究竟是解释为有符号还是无符号由编译器决定    段中的最大位数限制在一个整型之内,成员的内存分配从左到右还是从右到左未知    后面的位段不能够容纳与前面一个位段剩余空间时,可能直接接在前面的位段后面(内    存位置边界上形成重叠),也可能放在内存的下一个字。9.位段实现的功能都可以用移位和屏蔽来实现,在目标代码中,移位和屏蔽是必需的,    位段唯一好处源代码简洁,但是可移植性较弱
Complex
1.初始化必须是第一个元素,必须位于一对花括号内,如果类型不符,会转换(如果可能)并赋给第一个
Dynamic memory allocation
1.void *calloc(size_t num_elements,size_t element);void *malloc(size_t size);    void *realloc(void *ptr,size_t new_size);void free(void *pointer);    calloc 会初始化为0。free,realloc传递NULL作为参数无作用。分配不成功返回NULL    
Advanced pointers
1.指向指针的指针2.理解声明方法 1)推论声明  2)用于声明变量的表达式和普通的表达式在求值时使用相同的规则    int *f()   int (*f)()  int *(*f)()   int *f[]  int(*f[])()  int *(*f[])()    int f()[] f是一个函数,它的返回值是一个整形数组。它是非法的,函数不能返回数组    int f[]() f是一个数组,它的元素类型是返回整型的函数。非法的,数组元素长度相同,不可能是函数    unix系统cdecl程序可以转换声明和英语3.函数指针    初始化:int f(int );  int (*pf)(int) = &f;    调用函数: f(12)  (*pf)(12) 或者 pf(12)    f(12)简单调用函数。过程:函数名f首先被转换成一个函数指针,该指针指向函数在内存中的位置。    然后,函数调用操作符调用该函数,执行开始与这个地址的代码。所以,(*pf)(12)函数指针转换    成函数编译器又将其转换回去,pf(12)才是正道4.回调函数,java中策略模式,接口实现,例如Comparator,但java中可以用实现接口和泛型解决    类型的问题,C中只能是 void*,灵活但不安全。    在写用于函数指针调用的函数时一般参数为void*,注意强制转换。    强制类型转换会躲过一般的类型检测,必须格外注意类型的问题。    函数指针调用库函数,例如strcmp,编译器一般有警告,因为参数是void*,而不是char*5.转换表。汇编中TAB也经常这样用6.字符串是指针常量,字符串出现在表达式中的时候就是指针常量    转换二进制为字符 "0123456789ABCDEF"[value % 16];  *"xyz" 就是 x
Pretreatment
1. Operation of text Nature 2. Preprocessing symbols _file_ _line_ _date_ _time_ _stdc_3. #define can be more than one line, except the last line, the other line end to add backslashes. 4. In the macro definition, if the calling function does not add a semicolon to the end. Some statements are fine, but for example if, two semicolons appear with a problem 5. #define NAME (parameter-list) stuff. argument list the opening parenthesis and name must be next to each other, or become stuff6. The value is worth the macro definition of each parameter is enclosed in parentheses, the outermost brackets 7. A macro parameter and a # define definition can contain symbols for other # define definitions. A macro cannot appear recursive 8. Preprocessing does not carry out detection of string constant content.    Insert a macro parameter into a string constant in two methods 1) adjacent to the string auto-join attribute #define PRINT (format,value) printf ("Result:" FORMAT "\ n", VALUE) PRINT ("%d", +); 2. Use the preprocessor to convert macro parameters to Strings #argument会被翻译成 "argument" #define PRINT (Format,value) printf (#VALUE "is" FORMAT "\ n", VALUE) PRINT ("%d", + +); 9.## connects the symbols on either side of it into a symbol #define ADD_T0_SUM (sum_num,value) SUM # # Sum_num +=value add_t0_sum (5,25) s UM5 variable plus 2510. Macros and functions: Define simple work #define MAX (A, B) ((a) >    A):(B)) Consider the consumption of function calls, and the spatial functions that are used by macros like inline functions have restrictions on data types, such as above. Some task functions cannot be implemented, such as when a parameter is a data type.    11. Side effects of macro parameters, macro parameters can occur more than once in a macro definition, and the side effects of macro parameters may be dangerous. Common Lisp macro also has this problem, but its macro is really powerful, can easily solve Z=max (x++,y++) z= ((x + +) > (y++)?    (x + +): (y++)) The small value is increased one time, and the large increase is two times. It is not limited to changing the values of variables, such as GetChar (), as well as side effects. 12. Conditional compilation #if Constant-expression do not want to appear in the product, commissioning, maintenance needs statement #elif ... #else ... #endif. Constant-expresion (constant expression) is a job search by a preprocessor, not a 0 statement. For example assign macro #if defined (symbol) is equivalent to ifdef symbol, if!defined (symbol) is equivalent to ifndef symbol #if more powerful #if x>0 | | Defined (ABC) && defined (BCD) can be nested, 13. The compiler defines a series of standard location lookup function library header files,/user/include, You can add 14. Standard Requirements header file nesting support at least 8 layers, but there is no reason to let nesting more than two layers, it is difficult to judge the source files between the Real dependency Unix make utility must know these dependencies determine what to recompile after the file modification. #error #line #progma # Invalid command
Input and output functions
The 1.ANSI compiler allows the addition of functions on the base of the library, but if you care about portability, you should avoid 2.void perror (char const *message); stdio.h; a colon and error content is appended to the message 3. The standard library function saves the error code in an external integer variable errno (defined in errno.h) and passes this information to the user Program 4. The errno is set only if a library function fails. So we can not test errno value to determine if there is an error occurred 5.void exit (int status); stdlib.h; The status value returns an operating system that indicates whether the program is normal and that the value is the same as the integer state returned by main. Often in the perror after the call, really wrong can not endure. Nowhere to return 6. The vast majority of drains are fully buffered, meaning that reads and writes are actually copied from a buffer memory area to the data 7.printf distributed in the program for debugging.    However, the output of these functions is written to the buffer and will not be displayed immediately. If the program fails, the buffered output may not be actually written, and the result will be incorrect in the wrong place. Solution: printf ("something"); Fflush (stdout); immediate Fflush8. On systems where the external representation of a line of text differs from the standard of a newline character representing the end of text, the library function is responsible for translating 9.stdio.h declares a file structure for accessing a stream. Each stream corresponds to a file. 10. Each program runs, the system provides at least three streams, stdin,stdout,stderr, are pointers to the file structure of 11. Standard input and output and errors are the default locations, depending on the compiler, usually keyboards and terminals can redirect the program < data > Answer DOS and UNIX support 12.FILE *fopen (char const *name, char const *mode); The name of the file * variable is used to hold the return value of the fopen, which does not affect which file is opened. Name is a string that avoids the differences in each system. Text: R w a binary: RB WB AB Update: A +, read-write failure returns a null pointer, errno will prompt the nature of the problem, should always check the return value 13.    FILE *freopen (char const *filename,char const *mode,file *stream); To open or reopen the stream, first try to close STream, and then re-opens the stream with the specified filename and mode, fails back to Null14.int flose (FILE *f), returns 0 successfully, or the program that returns Eof15.fopen and fclose directly may result in file* changes, Cause fclose failure 16.int fgetc (FILE *stream); int getc (FILE *stream);    int GetChar (void); Reads a character and does not return EOF. The return value is int instead of char, because Eof17.int fputc (int character,file *stream), int putc (int character,file *stream), int putchar (int    character); The first parameter is the character to be printed, and before printing, the function cuts the integer parameter to an unsigned character value of Putchar (' abc '); only one character is printed, and which is determined by the compiler. Write to closed stream or other failure, return eof18.fgetc and FPUTC is function, Getc,putc,getchar,putchar, is macro 19.int ungetc (int character,file *stream);    Return the character to the stream in 20.char *fgets (char *buffer,int buffer_size,file *stream); The buffer reaches buffer_size-1 or reads a newline character and stops reading. The next call starts at the beginning of a character, regardless of whether the end is nil if the end of the file is reached before any characters are read, the buffer does not change, fgets returns NULL, otherwise it returns a pointer to the buffer 21.int fputs (char const *buffer,file *    stream); Buffer must contain a string, but it is not as fgets as a maximum of one row. When writing an error, return EOF, otherwise non-negative 22.char *gets (char *buffer), int puts (char const *buffer), and fgets,fputs similar, reserved for backwards compatibility, except that the get reads a row    , the newline character is not retained at the end of the line, and a newline character is added when the puts is written. Moreover, the get has no buffer length parameter, the extra characters will be written to the memory behind the buffer!! 23.int fscanf (FILE *stream,char const *format,...); int scanf (char const *format,...);    int sscanf (char const *string,char const *format,...);    Ellipses represent a variable-length list of pointers that are stored individually to the memory pointed to by these pointers. Will skip whitespace characters.    When the formatted string reaches the end or the input that is read no longer matches the type specified by the format string, the input stops, the number of input values is used as the return value, and no input returns EOF to the end. Format codes are preceded by a%, and can be followed by an optional asterisk (discard does not store this character), an optional width (non-negative integer, the limit is read for the length of the conversion, when the type length is longer than or shorter than the default length, does not specify a width error, always specifies more portability), an optional qualifier (                 H,L,L), and a format code of 24.       H l l d,i,n short long o,u,x unsigned short unsigned long e,f,g double long double25. Format code: C (char *) reads a single character, if given a wide Degrees, read the width of a, the end will not add nul, i,d (int *) signed, I based on the first character to determine the cardinality, u,o,x (unsigned *) u decimal, o octal, x hex e,f,g (float *) s (char *) A string    Non-null characters, found blank stop, automatically add nul [XXX] (char *) a circle of characters, found that the first character not in a given combination stop, automatically add nul, the list header can be added ^, is not in the composition, whether the support of the horizontal bar indicates the range of words Fuin compiler, such as%[a-z] The P (void *) input is expected to be a string of characters, and the conversion method varies by compiler, but the conversion results are returned by using p to print characters that are the same as the input (int *) and the number of characters that have been read by scanf from the input so far. %n converted characters are not countedWithin the scanf return value.    It itself does not consume input% to match the% in the input, the% is discarded 26.int fprintf (FILE *stream,char const *format,...);  int printf (char const *format,...); int sprintf (char *buffer,char const *format,...);    27.size_t fread (void *buffer,size_t size,size_t count,file *stream);    size_t fwrite (void *buffer,size_t size,size_t count,file *stream); The size is the number of bytes per element in the buffer, count is the number of elements read or written, and the buffer space is size*count so large that the number of elements (not bytes) that are actually sucked in or read. You can implement the operation of object flow in Java 28.int fflush (FILE *stream), forcing the data of a buffer of an output stream to be physically written. 29. General Data Room Linear write, long Ftell (FILE *stream), returns the current position of the stream, in the binary stream, this value is the current position distance from the file start position of the byte number offset, in the text stream, does not exactly represent the character number offset, because some systems will    The end-of-line character is translated but the return value of Ftell can always be used in the Fseek function.    int fseek (FILE *stream,long offset,int from), locates a stream and changes the position of the next operation. From:seek_end, offset bytes from the tail, can be negative. Seek_cur,offset can be negative. Seek_set, starting position, offset non-negative 30. Attempting to navigate to the beginning of the file is an error, locating to the end of the file and writing will extend the file, attempting to access a message that will result in the return of a "reach end of file." The binary stream may not support Seek_end, the text stream must be Seek_cur,seek_end,offset 0 if the from is Seek_set,offset must be ftell return value 31.fseek side effects: The end of the line indicates that the character is cleared. If the fseek is ungetc before, the returned character is discarded because theBit operation, it is no longer the next character. Positioning allows switching from write mode to read mode, or back to the open stream to update 32.void rewind (file *stream); Navigates to the beginning of the stream, while the clear stream error identifies the int fgetpos (file *stream,fpos_t *    position); int Fsetpos (FILE *stream,fpos_t const *position); Ftell and Fseek Alternatives, Fgetpos stores the current location to the Fpos_t,fsetpos settings file to fpos_t fpos_t indicates that the file location is not a standard definition, possibly an offset or not, 33.void setbuf (file *    Stream,char *buf); int setvbuf (FILE *stream,char *buf,int mod,size_t size); Must be executed before the stream is opened but not performed before any other operation, Setbuf sets an array of convection buffers, length bufsiz, defined in stdio.h. Developing a buffer for the stream itself prevents the I/O function library from dynamically allocating buffers for it.    BUF is null to close the buffer. Using an automatic array buffer for a stream may cause the stream to not shut down, but the array is already out of code, the memory is used by another function, the stream continues to use Setvbuf:mode to specify the type of buffering, _IOFBF specifies a fully buffered stream, _IONBF specifies a non-buffered stream, _ IOLBUF specifies a row buffer stream, that is, whenever a newline character is written to the buffer, the buffer is refreshed. BUF for Null,size must be 0, generally BUFSIZ34. stream error function; int feof (file *stream); Stream at end of file returns True. int ferror (FILE *stream), reports the error state of the stream, and returns true if any read-write errors occur. void Clearerr (file *stream); The error flag for the convection is reset 35. Temporary files: file *tmpfile (void), opened in wb+ mode, which makes it available for binary and text data.    If the file must be opened by another mode or opened by another program, it must be fopen and must be removed using remove when it is no longer needed. Char *tmpnam (char *name); creates the name of the temporary file. parameter is NULL, returns a pointer to a static array that contains the file name, otherwise specifiesAn array with a length of at least L_temnam, and the file name in the array that the returned pointer represents.    Tmp_max36.int Remove (char const *filename), int rename (char const *oldname,char const *NEWNAME) will be guaranteed; Successfully returns 0, otherwise 0 is not returned. The remove file is already open, and the result depends on the compiler. Rename exists newname, result compiler, Oldname still available
Standard library functions
1.stdlib.h int abs (int value); A long int labs (long int value), an ABS div_t div (int numerator,int denominator), the second parameter is the denominator, the first is the numerator.  The quotient and remainder, the structure of the div_t int quot;//quotient, int rem;//remainder ldiv_t ldiv (long int number,long int denom); 2.stdlib.h The following function produces a pseudo-random number int rand (void); 0-32767 in order to avoid each call to Rand for the same random list, void srand (unsigned int seed) is used to do the Seed srand ((unsigmaned int) time (0) for each day); 3.math.h double sin (double angle); cos....tan.....double asin (double value); Atan. Double atan2 (double x,double y); tangent of y/x. Both radians denote double sinh (double angle), ... cosh....tanh ..... 4.MATH.H double exp (double x);  Double log (double x); Double log10 (double x); 5.math.h floating-point representation double frexp (double value,int *exponent); calculates an exponent exponent and fractional fracion so Fraction*po    The value of W (2,exponent) equals value, where 0.5<=fraction<1.    Double Ldexp (double fraction,int exponent); return Fraction*pow (2,exponent); Double Modef (double value,double *ipart); The floating-point value is divided into integers *ipart and decimal return values 6.MATH.H Double pow (double x,double y); X's y-square double sqrt (doUble x); 7. Define domain errors demain error, the arguments are no longer within the domain of the function definition. Range error if the number of errors is too large or too small to represent a range of 8.double floor (double x);d ouble ceil (double x);d ouble fabs (double x);d ouble fmod (Double x,    Double y); Fmod returns the remainder of x divided by Y, and the quotient is limited to integer values.    Use double just to represent a larger range 9.stdlib.h string conversion int atoi (char const *string);    Long int Atol (char const *string);    Long int strtol (char const *STRING,CHAR **unused,int base);    unsigned long int strtoul (char const *STRING,CHAR **unsed,int base);    Double atof (char const *string);    Double strtod (char const *string,char **unused); The first parameter of any function that contains leading whitespace characters will be ignored, any illegal suffixes, and they will also be ignored for atoi and Atol execution cardinality is 10 operations. Strtol holds a pointer to the first character after the converted value, and if the second argument of the function is not NULL, the pointer is saved in the position pointed to by the second argument. This pointer allows the remainder of the string to be processed without guessing where the transition terminates. Base is the base of the conversion, if the cardinality is 0, any form used to write the integer literal is accepted, including the form of the specified number cardinality, such as 0x2af4,0377. Otherwise, the cardinality value should be 2 to 36 direct, for Radix 11-36, the letter a/a-z/z is interpreted as 10-35 if string cannot represent a valid value, returns 0, the function stores erange10.time.h clock_t clock (void) in the errno    , the program starts to run the processor consumes time, approximate value, wants the exact value to begin to call in Main, subtracts. Returns the number of times the processor clock ticks, wanting to divide the seconds by the constant clocks_per_sec. Too big to return -111.time_t time (time_t *returned_value); too large return-1, the standard does not specify the result in seconds, can not be used to determine the time elapsed, 12.char *ctime (time_t const *time_value); Returns a string, such as Sun Jul 4 04:02:28 1976\n\0; The spaces within the string are fixed, double difftime (time_t time1,time_t time2), calculation is poor, and converted to 13.struct TM *gmtime (time_t const *time_value); Convert Time to GMT, world coordinated Time struct TM *localtime (time_t const *time_value); Convert to local time, but standard no UTC and local time relationship STRUTC Tm{int Tm_sec;0-61;int t    M_min;0-59;int Tm_hour;0-23;int tm_mday;1-31; int Tm_mon;0-31;int tm_year;0-?; To add 1900;int wday;0-6;int tm_yday;0-356;int tm_isdat; daylight saving Time flag}14.char *asctime (struct TM const *TM_PTR); Returns the same format as CTime Size_    T strftime (char *string,size_t maxsize,char Const *FORMAT,STRUCT TM const *TM_PTR); Very flexible TM structure converted to string 15.time_t mktime (struct TM *tm_ptr); 16.setjmp.h int setjmp (jmp_buf state); void longjmp (jmp_buf state,int value); Similar to the goto mechanism first declares jmp_buf, and calls setjmp to initialize it, the return value is 0,setjmp to save the program state to the buffer, the function called the top-level function, call longjmp later, will cause the saved state recovery, SETJMP returns the longjmp parameter value17. Signal signal.h18.void abort (void); void Atexit (void (func) (void));    void exit (int status); AboRT does not normally terminate the program, triggering the SIGABRT signal. Atexit registers the exit signal, when the EIXT call, the registered function is called in the order of registration, then the stream buffer is flushed, the file is closed, and the Tmpfile file is deleted 19.assert.h void assert (int expression); False when printing information and terminating, #define NEBUG disables assertion 20.stdlib.h char *getenv (char const *name); Returns information about the name that is maintained by the operating system 21.stdlib.h void system (char c Onst *command); system execution, presence available, returns non 0 value, otherwise returns zero 22.void qsort (void *base,size_t n_elements,size_t El_size,int (*compare) (void    Const *,void const *)); void bsearch (void const *key,void const *base,size_t n_element,size_t el_size, int (*compare) (void const*,void cons T *));
Run-time environment
1.-S保留汇编代码2.参数按参数列表相反的顺序压入堆栈,这样第一个参数位于堆栈中参数的顶部    如果相反顺序,第一个参数距离帧指针的偏移量就和压入堆栈的参数数量有关。虽然编译器可以计算,但    可变实参列表就无法计算偏移量了3.函数三部分:函数序prologue,函数启动需要的工作。函数体body。函数跋epilogue,函数返回前清理堆栈

Summary of "C and pointers"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.