About sizeof string Calculation

Source: Internet
Author: User

1 # include
2 # include
3 # include
4 int main (INT argc, char ** argv)
5 {
6 char * Ss = "0123456789 ";
7 printf ("string sizeof (SS) is % d/N", sizeof (SS); // for the type, SS is Pointer
8 printf ("string sizeof (* ss) is % d/N", sizeof (* ss )); // * ss is the first character of the string
9 printf ("string sizeof (Wanglei) is % d/N", sizeof ("Wanglei ")); // at this time, Wanglei should be stored in the array by default.

the number of bytes that "Wanglei" occupies

10 printf ("string strlen (SS) is % d/N", strlen (SS); // strlen is not counted as '/0'
11
12 char SSS [20] = {"1234567890 "};
13 printf ("array sizeof (SSS) is % d/N", sizeof (SSS ));
14 printf ("array strlen (SSS) is % d/N", strlen (SSS ));
15}
In short, sizeof is the number of bytes occupied by computation.

 

String sizeof (SS) is 4
String sizeof (* ss) is 1
String sizeof (Wanglei) is 8
String strlen (SS) is 10
Array sizeof (SSS) is 20
Array strlen (SSS) is 10

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.