Strlen sizeof strcat strcpy, strcatstrcpy

Source: Internet
Author: User

Strlen sizeof strcat strcpy, strcatstrcpy

Strlen (p ):

  • Calculate the length of p pointing to the string (starting from the current position of p), excluding the ending character '\ 0 ';
  • P can be declared as char * p or char p []. Both forms of strlen can be correctly calculated.

Sizeof (p ):

  • Sizeof is an operator, a non-function, and its value is determined during the compilation period. Therefore, when p is declared as a Type pointer, sizeof cannot determine the size of the content to be pointed to during compilation, therefore, the returned value is the size of the pointer type;

When p is declared as an array of a type, sizeof can determine the size of the content to be pointed to during compilation. Therefore, the returned value is the size of the array;

 

Strcat (p1, p2) and strcpy (p1, p2)

Similarities:

  • P1 must be a variable pointer to the content, such as char p1 []
  • When the character currently pointed to by p1 is the ending character ('\ 0'), it is connected directly with the p2 content or overwritten at the current position of p1 and after

Differences:

  • When the character currently pointed to by p1 is not the ending character ('\ 0'), strcat automatically connects the content of p2 at and after the ending character; strcpy directly uses p2 content to overwrite the content currently pointed to by p1.

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.