Understanding of C-language & address-taking operators

Source: Internet
Author: User

For the & operator in C, the Baidu Encyclopedia is defined as: (&P) is an operation that returns the address opened at the time when P was declared, but according to my observations on the code, I think the & operator is not just the function of returning the address;

For example:

int a = 1;
Suppose the address of a is 0x7dfe88
int *p = (int *) 0x7dfe88;

int num = 1;
int *P1 = #

The above is a simple code to the pointer p,p1 assignment, 0X7DFE88 is a simple hexadecimal address, but when the address to the pointer must be accompanied by a strong (int *), if not enhanced, then the compiler will warn (warning C4047: "Initialization": "Int * "int" is different from the indirect level), but using the & operator does not need to add any strong turn to compile through, the & operator is never to get the address so simple, the "=" assignment operator is right-to-left, stating "=" to the right is also a pointer, So this assumes that the & operator takes out the address of NUM and generates a temporary pointer based on the type of Num.

Based on assumptions, write the following code validation:

int num = 1;
Double *P1 = #

Result compiler reported "warning C4133:" Initialization: "int *" to "double *" type incompatible "error. So my hypothesis has a certain truth.

Sum up:

(&P) is an operation that returns a pointer to the address that was opened at the time when P was declared, and the type of the pointer is the pointer type for the type of p. (Just my own opinion)

Understanding of C-language & address-taking operators

Related Article

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.