In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the role of C language * and & in operating linear tables". The content of the explanation in this article is simple and clear and easy to learn and understand. let's study and learn "what is the role of C language * and & in operating linear tables"?
In the data structure linear table chapter, there are these methods of operation (Operation) for linear tables:
/ * initialize the operation to create an empty linear table ListEmpty / ListEmpty (L); / * determine whether the linear table is empty; if the linear table is empty, the return value is true, otherwise return false*/ ClearList (* L); / * clear the linear table * / GetElem; / * return the value of the first position element in the property table L to eBay / LocateElem (LMagne) / * find the element equal to the given value e in the linear table L, and return the serial number of the element in the table if the search is successful; otherwise, return 0 to indicate failure * / ListInsert (* L ~ e); / * insert the element eBay / ListDelete (* L ~ e) in position I (* L ~); / * delete the I location elements and return their value * / ListLength (L) with e; / * return the number of elements in the linear table L * /
We can roughly divide the above functions into two categories, one of which is not * in the parameter list, for example: ListEmpty (L)
The other type has a (*) sign before L or e. Why on earth is it?
We can get inspiration from the following code
# include # include void test1 (int apenint b) {int canti0; cymb; Bologna; astata; printf ("% d\ n", a); printf ("% d\ n", b);} int main () {int aqum1; int baud 2; test1 (aQuinb); printf ("% d\ n", a); printf ("% d\ n", b);}
The running result is as follows, it can be seen that the exchange value of arecroy b in test1 as a parameter has no effect on the actual parameters in main function.
two
one
one
two
Process returned 0 (0x0) execution time: 0.118 s
Press any key to continue.
Let's make some changes to the above code to observe the result.
# include # include void test1 (int * aPowerint * b) {int cantilever; cantilever; * bimoda; * astatc; printf ("% d\ n", & a); printf ("% d\ n", & b);} int main () {int astat1; int bau2; test1 (& a); printf ("% d\ n", a); printf ("% d\ n", b); return 0;}
6422000
6422008
two
one
Process returned 0 (0x0) execution time: 0.033 s
Press any key to continue.
Obviously, this time the test1 () method has an impact on the arguments to the main function, because the current test () method directly modifies the data fields of storage units with addresses 6422000 and 6422008.
When we go back to the operation of linear tables, we will suddenly realize. For example, if you don't add * to ListInsert, then L stays in the function forever as a local variable: ListInsert, which can't actually change. Add * to ensure that L is brought out. We only need to add'*'to the shape when the method is defined and'& 'when the method is called to achieve the desired results.
Thinking: another solution: is it possible to define a List Insert () method so that the return value is the modified linked list L?
List Insert (List Lmenint iMagnum ElemtType e) {/ * here for inserting the linked list * / return List;// note that the returned list value has been modified}
However, there is a drawback: when insertion occurs in the header, L must point to the new node, otherwise the address still points to the original header node. The solution is to insert a meaningless header node b before the first node an of the list, so that every time you want to insert an element in the header, you only need to insert it between aline b.
Note: in C language, * a points to the data field of a, and & reads the address of a.
Thank you for your reading, the above is the content of "C language * and & what is the role of operating linear tables". After the study of this article, I believe you have a deeper understanding of the role of C language * and & in operating linear tables, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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: 243
*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.