Some common differences (similar in functionality) in C + +

Source: Internet
Author: User

The difference between 1.sizeof and strlen

1) The result type of the sizeof operator is size_t, and its typedef in the header file is the unsigned int type. This type guarantees that the byte size of the largest object established by the implementation can be accommodated

2) sizeof is an operator, strlen is a function

3) sizeof can be used to type parameters, strlen can only be used char * parameter, and must be "to" end, sizeof can also be a function to do parameters.

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

5) Most compilers have calculated sizeof at compile time, which is the length of the type or variable. This is why sizeof (x) can be used to define the number of dimensions of an array

6) The result of the strlen is calculated at run time to calculate the length of the string, not the size of the class-occupied village.

7) After sizeof if the type must be parentheses, if the variable name can be without parentheses, this is because sizeof is an operator instead of a function

8) When a struct-type type or variable is used, sizeof returns the actual size, and when a static array of spaces is used, sizeof returns the dimensions of all arrays, and the sizeof operator cannot return the dimensions of an array or an outer array that is dynamically allocated

9) When an array is passed as a parameter to a function, it is a pointer instead of an array, passing the first address of the array

  

Some common differences (similar in functionality) in C + +

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.