In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to use const in C language, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to use const in C language. Let's take a look at it.
Const can say a constant declared keyword, such as const int aquifer 2; variable an is a constant, the value of a can not be changed, this change is in a certain sense can not be changed. It is said that the change of value cannot be changed directly through the symbol a. But in fact, the value of a may change. Examples are as follows:
# include int main () {const int astat3; int* p = (int*) & a; * pendant 100; printf ("% d", a); return 0;}
In this way, the value of an is changed.
Const can also say a read-only keyword, such as
Int integerArray [10] = {0}; const int* pointer=integerArray
Here pointer is a pointer variable pointing to a constant variable. The pointer point may change, but the value of the variable it points to cannot be changed directly through pointer. Such as:
* (pendant 1) = 2
This is not allowed. But if there is another array integerArray1,p=integerArray1 can have. There are also pointed to the variable can not be changed, this immutable is a certain sense of change. Examples are as follows:
# include int main () {int array [10] = {0}; const int* pointer=array; int* pointer1= (int*) pointer; pointer1 [0] = 1; printf ("% d", array [0]); return 0;}
The above example shows that array cannot be changed directly through pointer, but array may be changed indirectly through pointer.
Now that there is a const declaration constant pointer, its declaration is not in the form of a pointer to a constant. Its declaration form is: int* const pointer;. The direction of the constant pointer cannot be changed during programming. Therefore, the constant pointer must assign an initial value to it when it is declared.
Otherwise, it cannot be assigned directly. However, if it must be assigned a certain value, it is possible. Examples are as follows:
# include int main () {int astat2; int* const p; int** p1 = (int**) & p; * p1roomia; printf ("% d", * p); return 0;}
After the above introduction, I believe it is not difficult to write the declaration of the constant pointer to the constant. Its declarative form: cont int* const p; it is not used as too much introduction, the constant pointer to the constant is the composition of the pointer to the constant and the constant pointer.
This is the end of the article on "how to use const in C language". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use const in C language". If you want to learn more, you are 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.
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.