In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 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 reason for the use of pointing structure pointers in c language". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the reason for the use of pointing structure pointers in the c language?"
1. The pointer to the structure is usually easier to control than the structure itself.
2. The early structure cannot be passed to the function as an argument, but a pointer to the structure can be passed.
3. Even if you can pass the structure, passing the pointer is usually more efficient.
4. Some structures used to represent data contain pointers to other structures.
Example
# include # define LEN 20 struct names / / define the structure names {char first [LEN]; char last [LEN];}; struct guy / / define the structure guy {struct names handle; char favfood [LEN]; char job [LEN]; float income;} Int main (void) {struct guy fellow [2] = {/ / this is a structural nesting in which the names structure / / initialization structure array fellow is embedded in the guy structure Each element is a structural variable {{"Ewen", "Villard"}, "girlled salmon", "personality coach", 68112.00}, {{"Rodney", "Swillbelly"}, "tripe", "tabloid editor", 432400.00}} Struct guy * him; / / this is a pointer to the structure printf ("address # 1 address% p # 2 printf% p\ n", & fellow [0], & fellow [1]); him = & fellow [0]; / / tells the compiler where the pointer points to printf ("pointer # 1 printf% p # 2printf% p\ n", him,him+1) / / two addresses printf ("him- > income is $% .2f: (* him). Income is $% .2f\ n", him- > income, (* him) .income); / / 68112.00 / / points to the next structure, him plus 1 equals the address pointed to by him plus 84. The names structure takes 40 bytes, favfood 20 bytes, handle 20 bytes, and float 4 bytes, so the address will be added 84 him++; printf ("him- > favfood is% s: him- > handle.last is% s\ n", him- > favfood,him- > handle.last); / / because of the above him++, it points to favfood1 [1], return 0 } the output is PS D:\ Code\ C\ structure > cd "d:\ Code\ C\ structure\"; if ($?) {gcc structDemo02.c-o structDemo02} If ($?) {.\ structDemo02} address # 1:000000000061FD70 # 2:000000000061FDC4pointer # 1:000000000061FD70 # 2virtual 0000000061FDC4him2-> income is $68112.00: (* him). Income is $68112.00 him-> favfood is tripe: him- > handle.last is Swillbelly so far, I believe you have a deeper understanding of "what is the reason for using structural pointers in c language". 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
© 2024 shulou.com SLNews company. All rights reserved.