In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use the sizeof function in C language. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
I. brief introduction of sizeof function
In C language, char string is also a very important data type. In addition to using sizeof function to obtain string length, we can also use sizeof function to obtain string length.
String: a string constant is usually represented by a string of characters enclosed by a pair of double quotation marks. The string ends with the escape character'\ 0' by default, and the string constant cannot be modified.
The sizeof function scans the entire string until the first string Terminator'\ 0' is encountered, and then returns the counter value (length includes'\ 0')
/ * * description: * [in] s: string * * return value: return the length of the string s. Note that the length returned includes\ 0*/int sizeof (char * s).
Note: the length returned by sizeof does not include'\ 0', so when getting the string length, the strlen function returns a byte less than the value.
II. Sizeof function practice / * / / @ Author: ape programming / / @ Blog (personal blog address) : www.codersrc.com//@File:C language tutorial-C language sizeof function / / @ Time:2021/06/02 08:00//@Motto: it is impossible to reach thousands of miles without long steps. Do not accumulate a small stream can not become a river and sea, the program of wonderful life needs to unremittingly accumulate! / * / # include "stdafx.h" # include#includevoid main () {char p [] = "www.codersrc.com" Printf ("string:% s length:% d\ n", p, sizeof (p)); char p1 [] = "www"; printf ("string:% s length:% d\ n", p1, sizeof (p1)); char p2 [] = "0123456789"; printf ("string:% s length:% d\ n", p2, sizeof (p2)); system ("pause");}
Output:
String: www.codersrc.com length: 17
String: www length: 4
String: 0123456789 length: 11
Please press any key to continue. . .
Thank you for reading! This is the end of the article on "how to use the sizeof function in C language". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.