In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "what is the difference between single quotation marks and double quotation marks in C language". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the difference between single quotation marks and double quotation marks in C language" can help you solve your doubts.
The single quotation marks in C language are used to represent the literal amount of characters and are compiled into the corresponding ASCII code.
The double quotation marks in C language are used to indicate the literal amount of string and are compiled to the corresponding memory address.
'a "represents the literal amount of characters, accounting for one byte in memory, and'a" + 1 represents the ASCII code of'a "plus 1, resulting in'b".
"a" represents the literal amount of the string, accounting for two bytes in memory, and "a" + 1 represents a pointer operation that points to the "a" Terminator'"
Analysis: is the following procedure legal?
Char* p1 = 1; / / p1 points to address 0x00000001char* p2 = "1"; / / p2 points to address 0x00000031charr * p3 = "1"; / / p3 points to address 0x080484d0
These three statements are legal and there will be warnings, but in essence they do not affect the operation of the program.
If the program is changed like this:
# include int main () {char* p1 = 1; char* p2 = "1"; char* p3 = "1"; printf ("% sforce% s, p1, p2, p3); / / segment error printf ("); / / segment error printf ("); return 0;}
Tips:
1. The literal number of characters is compiled into the corresponding ASCII code.
2. The literal amount of the string is compiled to the corresponding memory address
3. The low address space of memory cannot be accessed at will in the program.
As you can see in the image above, all address spaces lower than 0x08048000 are inaccessible, so neither p1 nor p2 can access the memory address, resulting in a segment error.
Program example analysis:
Char c = "string"
In fact, this is obviously wrong, because the string is compiled to the corresponding memory address, and the memory address accounts for 4 bytes, but c occupies only one byte, resulting in truncation, so generally for strings, we use pointers to point to
Char* p = "string"; read here, this article "what is the difference between single quotation marks and double quotes in C language" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.