What is the address operator in C language?

烟雨青岚
Release: 2020-07-03 10:29:14
Original
23145 people have browsed it

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.

What is the address operator in C language?

The address operator in C language is "&"

Example:

#include 
int main(void)
{
    int a = 0;
    int *p = &a;
    printf("The value is: %d/n", *p);
    return 0;
}
Copy after login

& 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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!