In C language, (asterisk) is used for indirect addressing and value, while & (address character) is used for address and reference. Get the value pointed to by the variable or pointer, used to modify the value and declare the pointer variable; & Get the variable address, used to assign the address to the pointer variable and pass the address as a function parameter.
The difference between * and & in C language
The symbols * and & are different operations in C language Symbols, used for different purposes:
Meaning:
Purpose:
Asterisk*:
Address symbol &:
Example:
int main() { int x = 10; int *ptr = &x; // ptr指向x的地址 // 获取x的值 printf("x = %d\n", x); // 使用指针获取x的值 printf("*ptr = %d\n", *ptr); // 使用指针修改x的值 *ptr = 20; printf("x = %d\n", x); // x的值已经改变为20 return 0; }
Note:
The above is the detailed content of The difference between * and & in C language. For more information, please follow other related articles on the PHP Chinese website!