Home  >  Article  >  Backend Development  >  What does & mean in C language?

What does & mean in C language?

Guanhui
GuanhuiOriginal
2020-06-12 14:11:5645799browse

What does & mean in C language?

What does & mean in C language?

In C language & can be used as a "bitwise AND" or "address-taking" operator. The bitwise AND operator is also a binary operator. Its function is to correspond to the two numbers involved in the operation. The binary AND of , and the address operator is a unary operator, which will set the operation result to the address of the right operand.

The bitwise AND operator

is to AND the binary numbers according to the corresponding bits to obtain a new binary number. 1 and 0 are 0; 1 and 1 are 1; 0 and 0 are 0.

The analysis is as follows:

is the AND of each bit of binary.

For example: 1010 0011& 0000 1111, the result is 0000 0011. That is to say, going with 0 is equivalent to clearing that digit to 0, and going with 1 is equivalent to keeping that bit.



What does & mean in C language?

Get address operator

For The & operator in C language, definition: (&p) is an operation that returns the address opened when p was declared; but based on my observation of the code, I feel that the & operator is not just a function of returning the address;

For example:

int a = 1;
//假设a的地址是0x7dfe88
int *p = (int *)0x7dfe88;
int num = 1;
int *p1 = #

The above is a simple code for assigning values ​​​​to pointers p and p1. 0x7dfe88 is a simple hexadecimal address, but when the address is converted to a pointer, it must be added Forced conversion (int *); if the conversion is not performed, the compiler will issue a warning (warning C4047: "Initialization": "int *" and "int" have different indirection levels); but when using the & operator to obtain the address However, it can be compiled and passed without any forced conversion. This shows that the & operator is by no means as simple as obtaining an address. The "=" assignment operator operates from right to left, which shows that the right side of "=" is also a pointer. So here we assume that the & operator will take out the address of num and generate a temporary pointer based on the type of num.

Based on the hypothesis, write the following code to verify:

int num = 1;
double *p1 = #

As a result, the compiler reported the error "warning C4133: "Initialization": type incompatibility from "int *" to "double *"" . So there is some truth to my hypothesis.

Recommended tutorial: "C#"

The above is the detailed content of What does & mean in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn