sizeof () and strlen (1)

Source: Internet
Author: User

sizeof function:

The number of bytes, such as the int type is 4 bytes under the 32 platform, Char is 1 bytes, and any type of pointer is 4 bytes.

Stelen function:

The length of the string, not including '/'.

The following is an example of distinguishing two functions from one-dimensional and two-dimensional arrays:

(1) One-dimensional arrays

int a[] = {1, 2, 3, 4}; printf ("%d\n", sizeof (a)); printf ("%d\n", sizeof (A + 0));p rintf ("%d\n", sizeof (*a));p rintf ("%d\n", sizeof (A + 1));p rintf ("%d\n", sizeof (a[1])); printf ("%d\n", sizeof (&a)); printf ("%d\n", sizeof (&a + 1));p rintf ("%d\n", sizeof (&a[0]));p rintf ("%d\n", sizeof (&a[0] + 1));

Output Result:

16

4

4

4

4

4

4

4

Please press any key to continue ...

Analytical:

(2) Two-dimensional arrays

int a[3][4] = {0};p rintf ("%d\n", sizeof (a));p rintf ("%d\n", sizeof (A[0][0]));p rintf ("%d\n", sizeof (A[0]));p rintf ("%d\ n ", sizeof (A[0] + 1));p rintf ("%d\n ", sizeof (A + 1));p rintf ("%d\n ", sizeof (&a[0] + 1));p rintf ("%d\n ", sizeof (*a)); printf ("%d\n", sizeof (a[3]));

Output Result:

48

4

16

4

4

4

16

16

Please press any key to continue ...

Analysis of the next article sizeof () and strlen (2)

sizeof () and strlen (1)

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.