In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
In C language, variable address is often compiled piecemeal active assignment, for our users, we do not know the detailed address of a variable. So we define a pointer variable p, and give the address of the common variable a directly to the pointer variable p is p =&a; this is written.
About the definition of pointer variable p say and initialize, have two kinds of methods commonly, these two kinds of methods, beginner is very easy intermingled, accordingly this center does not have other method, be assimilate, remember can.
Solution 1: Stop initializing assignment directly when defining.
unsigned char a; unsigned char *p = &a;
Option 2: Stop assigning after defining.
unsigned char a; unsigned char *p; p = &a;
Everyone will see the difference between these two ways of writing carefully, and they are mostly accurate. We add a * in front of the pointer variable, and this *p means that this p is a pointer variable, not a common variable, it is specifically used to register the variable address. In addition, we define the time division of *p by unsigned char, which means that the variable type pointed to by this pointer is unsigned char.
Pointer variables seem to be relatively easy to understand, and everyone can easily hear clearly. So why do many people confuse pointers? Because in C language, there are some operations and definitions, they are different, many students are not clear about their differences, the pointer has been learning badly. Here I want to emphasize two differences, just make these two differences clear, at least pointer variables this part is not a result. These two key points are now mastered by everyone, and they can be remembered directly. By understanding, they can mix concepts.
The first major difference is between the pointer variable p and the popular variable a.
We define a variable a, and we can assign a = 1 or a = 2 to a variable a.
We define a pointer variable p, others also define a common variable a=1, common variable b=2, then this pointer variable can point to the address of a, can also point to the address of b, can be written p = &a, can also be written p = &b, but it is not written p = 1 or p = 2 or p = a, these three expressions are mostly wrong.
Therefore, this central, do not see the definition of *p before the time there is an unsigned char type, on the wrong assignment p=1, this only clarifies that p points to the variable is the unsigned char type, and p itself, is a pointer variable, Fu Cheng to assign it a popular value or variable, later we will directly call the pointer variable pointer, everyone should pay attention to this small detail.
The first difference seems relatively easy to understand, and there is a second major difference that must be remembered clearly.
The second major difference is the difference between defining pointer variables *p and valuing operations * p.
The symbol "*" has three uses in our C language. The first use is very complicated. The multiplication operation uses this symbol, so we won't talk about it here.
The second usage is to define the time division of pointer variables, such as unsigned char *p, which means that p is a pointer variable, not a common variable.
There is also a third use, which is the value operation, and the definition of pointer variables are completely different things, for example:
unsigned char a = 1; unsigned char b = 2; unsigned char *p; p = &a; b = *p;
After these two steps, the value of b becomes 1. In this code,&a represents the address of the variable taken a, after sending this address to p, and then using *p to represent the value of the variable taken the address pointed to by the pointer variable p, and sending this value to b, the final result is equivalent to b=a. The difference is *p, the position of the definition is to define the pointer variable, and it is the value operation in the implementation code.
These two main differences can be repeated three or four times, and when they are made clear, the door of the pointer will be stepped out smoothly. As for the specific usage, we will gradually become familiar with it after using it more.
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
* * General * * owner = Peter Randomcontact = some@address.nowheremailhost = my.mail.hostsendmail
© 2024 shulou.com SLNews company. All rights reserved.