Home >Backend Development >C#.Net Tutorial >The difference between *a and a in c language
In C language, a is a pointer to the memory address of variable a, and a is an ordinary variable. a stores the value in a, and a stores the value of itself. a accesses the value pointed to by dereferencing it, while a accesses its own value directly. &a returns the memory address of a, while a returns the memory address pointing to the value.
The difference between *a and a in c language
In c language, *a
and a
are two different concepts. The main differences between them are as follows:
*a
is a pointer toa
is a pointer to the memory address of a variable; and a
is an ordinary variable. *a
is the value stored in the a
variable; and the value of a
itself. *a
can access the value it points to through the dereference operator (*
); and a
Only its own value can be accessed directly. &a
returns the memory address of the a
variable; and *a
returns the a
variable The memory address of the stored value. Detailed explanation:
*a
represents a pointer to the memory address of variable a
. The value stored at that memory address can be accessed through the dereference operator (*
). a
represents an ordinary variable, which stores a specific value. *
) is used to access the value pointed to by the pointer. For example, *a
means taking the value stored in the memory address pointed to by the a
pointer. &
) is used to obtain the memory address of a variable. For example, &a
returns the memory address of the a
variable. Example:
<code class="c">int a = 10; int *p = &a; printf("变量 a 的值:%d\n", a); printf("指向 a 的指针 p 的值:%d\n", *p);</code>
Output:
<code>变量 a 的值:10 指向 a 的指针 p 的值:10</code>
In this example, a
is a stored value of 10 The variable, p
is a pointer to the memory address of the a
variable. *p
Dereference the pointer and return the value stored in the a
variable, which is 10.
The above is the detailed content of The difference between *a and a in c language. For more information, please follow other related articles on the PHP Chinese website!