In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about an example analysis of the differences between the multiple definitions of the & and * symbols in C++ Primer and int* p and int* p. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Symbols such as & and * can be used either as operators in an expression or as part of a declaration. The context of the symbol determines the meaning of the symbol:
Int I = 42 int & r = I; / / & appears immediately after the type name, so it is part of the declaration, r is a reference to int * p; / / * appears immediately after the type name, so it is part of the declaration, p is a pointer int = & I; / / & appears in the expression and is an address character * p = I / / * appears in the expression as a de-citation character int & R2 = * p; / & is part of the declaration, and * is a de-citation character
In declarative statements, & and * are used to form compound types; in expressions, their roles are transformed into operators. Although it appears in different scenes
It is the same symbol, but because the meaning is completely different, we can treat them as different symbols.
According to C++Primer:
For int* p (which is legal but misleading), the basic data type is int, followed by * is actually a declarative. Different declarants can be used after a set of common data types. For example:
Int I = 1024, * p = & I, & r = I; / / I is a data of type int, p is an int pointer, and r is an int reference.
For int* p, it has the same meaning as int* p, which represents a pointer variable p of type int.
But it is easier to understand that declarants are followed by variable names. Otherwise, it may be misleading:
For example
Int* p1, p2; means that p1 is an int pointer and p2 is an int variable. Instead of p1 and p2 are pointer variables, they share the basic data type part.
If it is written as int * p1dp2; it has exactly the same meaning as the above expression, but it is clearer and will not be misleading.
However, for the use of the above two writing methods, it mainly depends on personal habits, but it is best not to mix them.
Thank you for reading! This is the end of this article on "an example analysis of the difference between the multiple definitions of & and * symbols in C++ Primer and int* p and int* p". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.