Basic review of C language 1

Source: Internet
Author: User
Tags define function function prototype

    • The difference between strlen () and sizeof ()

      1. sizeof () is an operator that can calculate the size of any type (including the function type).

2.strlen () is a function that requires the introduction of a header file <string.h>, which can only calculate the size of a string with the char* type ending with '% '.

3. The parameters of the array do sizeof () do not degenerate, but the passed to strlen () is degraded to a pointer.

4. The results of the strlen are calculated at run time, and are used to calculate the length of the string, not the size of the memory.

5. After sizeof, if the type must be bracketed, if the variable name can be non-parenthesized. This is because sizeof is an operator and not a function.

    • memset () memcpy () memcmp () memmove (), MEMCHR () implement memory overwrite issues

      1. memcpy ()

Function prototypes: void *memcpy (void *dest, void const *SRC, size_tlength);

Its function is to copy the length bytes from the starting position of SRC to dest;

It can replicate any type of value;

If there is overlap in the dest,src, the result is not predictable.

2. Memmove ()

Function prototypes: void *memmove (void *dest,void const *SRC, size_tlength);

Similar to memcpy, only their dest,src memory can overlap. Because the content in SRC is first copied to a temporary location when implemented. So the speed is slower than memcpy.

3.MEMCMP ()

function prototypes: int memcmp (void const *a,void const *b, size_tlength);

The function function is to compare two segments of memory, and the length of the comparison is byte. The return type of the function is the same as the strcmp;

Comparisons are made by unsigned bytes.

4.memset ()

Function prototype: void *memset (void *a, int ch, size_t length);

The function function is to start at the first address of memory a a total length byte is set to the character Ch.

5.MEMCHR ()

Function prototype: void *memchr (void const *a, int ch, size_t length);

The function function is to find the first occurrence of the character Ch from the starting position of a, and return a pointer to that position, which

A total of length bytes is searched, and if not found within this range, NULL is returned.

    • Atoi () Atol atof () implementation

Header file #include <stdlib.h>

1. atoi function (converts a string to an integer number)

define function: int atoi (const char * ptr);

Function Description: Atoi () scans the parameter PTR string and skips the preceding space character until a number or sign is encountered.

Does the conversion, and then encounters a non-numeric or string ending (' + ') before ending the conversion and returning the result

2. itoa function (converts an integer to a string)

Define function: char* itoa (int value,char*string,int radix);

Function Description: int value is converted integer, char *string converted to stored character array, int radix converted to binary

Number, such as 2,8,10,16.

Note that atoi is a standard library function, Itoa is not, you can use the sprintf () a function instead of itoa.

3. atof function (converts a string to a floating-point type)

Define function: Double atof (const char* PTR);

Function Description: Atof () scans the parameter PTR string, skips the preceding space character until it encounters a number or sign.

The conversion is not completed until the non-numeric or string ends (' \ \ '). Parameter ptr string can contain sign, decimal point e (E)

To represent an exponential portion, such as 123.456 or 123e-2. The return value returns the number of converted floating-point types.

4. atol (Convert string to growth integer)

Define function: Long atol (const char* PTR);

Function Description: Atol () scans the parameter PTR string, skips the preceding space character until it encounters a number or sign.

Starts the conversion, and then encounters a non-numeric or string ending (' + ') before ending the conversion and returning the result.

5. GCVT (Converts a floating-point number to a string, rounding)

Define function: Char *gcvt (double Number,size_tndigits,char *buf);

Function Description: GCVT () is used to convert the parameter number to an ASCII string, and the parameter ndigits indicates how many digits are displayed.

GCVT () differs from ECVT () and FCVT () in that the string converted by GCVT () contains either a decimal point or a positive or negative symbol. If the conversion succeeds, turn

The string that is replaced is placed in the space indicated by the parameter buf pointer.







This article is from the "13187791" blog, please be sure to keep this source http://13197791.blog.51cto.com/13187791/1954501

Basic review of C language 1

Related Article

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.