In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "pointer pointing in C++ and the usage of the const keyword", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "pointer pointing in C++ and the usage of the const keyword".
1.
Const char* s = "Mitch Hong"
Here, first of all, s is a pointer to the char type, and const is placed in front of the type char*, indicating that the value * s pointed to by the pointer variable cannot be modified, that is, nothing else can be placed in the address that s points to, but s itself can point to another address.
two。
Char* const s = "Mitch Hong"
Here, first of all, s is still a pointer to the char type, but const is placed after the type char*, which means that the pointer variable s cannot be modified, that is, s cannot point to other addresses, but other values can be placed on the address that s points to, that is, * s can be modified.
So let's take a more complicated one.
Sometimes we may need a global variable so that multiple functions can use the same data block (such as an array of 12-month share names). To prevent it from being modified, we can use the const keyword to prevent the data from being modified.
Const char* const Months [12] =
{
"January", "February", "March", "April", "May"
"June", "July", "August", "September", "October"
"November", "Decmber"
}
Months is an array of 12 elements, and each element in the array is a pointer to the char type, each pointing to 12 string constants.
The first const prevents * (Months [I]) from being modified, that is, to prevent the string inside from being modified.
The second const prevents Months [I] from being modified, that is, to prevent Months [I] from pointing to other addresses.
So the two const together can prevent the whole Months from being modified.
At this point, I believe you have a deeper understanding of "pointer pointing in C++ and the usage of the const keyword". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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
This thing is so powerful, www.spirent.com network equipment stress test.
© 2024 shulou.com SLNews company. All rights reserved.