Meaning of (unsigned int) & amp; in C ++

Source: Internet
Author: User

Int main ()

{
Using namespace std;
Int I = 20;
Int m = (unsigned int) & I; // note the & Symbol
Cout <m <endl;
}

&: Indicates the meaning of the reference, indicating that m is an alias of I, which is equivalent to a small name of a person.


Let's look at the following example:

# Include

 
  
# Define FIND (struc, e) (int) & (struc *) 0)-> e) typedef struct {int a; char B [20]; double ccc ;} stu; int main () {printf ("% d \ n", FIND (stu, B [0]); printf ("% d \ n", FIND (stu, ccc); return 0 ;}

 

A macro FIND is defined here to FIND the offset between a variable in struc and struc.

(Struc *) 0 indicates to forcibly convert the constant 0 to the address pointed to by the struc * pointer;

& (Struc &) 0)-> e) indicates the address of e, a member of struc * 0.

Output result: 4 24


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.