Home >Backend Development >C#.Net Tutorial >What is the address operator in C language?
The address operator in C language is "&". "&" acts as a unary operator, and the result is the address of the right operand object; the address itself is an abstract concept used to represent the logical location of the object in memory.
The address operator in C language is "&"
Example:
#include <stdio.h> int main(void) { int a = 0; int *p = &a; printf("The value is: %d/n", *p); return 0; }
& as a unary operator, the result is the address of the right operand object.
For example, &x returns the address of x.
The address itself is an abstract concept used to represent the logical location of an object in memory. As for the object, LZ now only needs to know that it contains constants, variables and other data.
scanf("%d,%d",&x,&y);
The &x here represents the address of x, and &y represents the address of y. scanf receives the address, and then processes the information read from the keyboard (more precisely, the stdin input stream buffer) in the form of a format string and stores it in the received address. For pure C, the parameters of a function can only be value parameters instead of variable parameters. Changes to the parameters within the function only affect the parameters themselves and not the actual parameters when the function is called (in other words, what is inside the function is just a copy). Therefore, x itself cannot be passed to scanf here. You need to use the address &x to specify the location where it needs to be stored, so that the value can be stored in x.
After systematically learning functions and pointers to transfer function parameters, LZ should have a clearer understanding of this.
As for the work of reading the keyboard, it is done by the compilation environment (including the bottom layer of the operating system) and has nothing to do with the C language itself
Recommended tutorial: "C Language"
The above is the detailed content of What is the address operator in C language?. For more information, please follow other related articles on the PHP Chinese website!