取地址符和解引用符的区别_(&)和解引用(*)运算符的地址以及C中的指针...

取地址符和解引用符的区别

Here, we are discussing about the two most useful operators with the pointers, why and how they are used?

在这里,我们用指针讨论两个最有用的运算符 ,为什么以及如何使用它们?

1)运营商地址(&) (1 ) The Address of Operator (&))

It is an "address of" operator which returns the address of any variable. The statement &var1 represents the address of var1 variable. Since it can be used anywhere but with the pointers, it is required to use for initializing the pointer with the address of another variable.

它是一个“地址”运算符 ,它返回任何变量的地址。 语句&var1代表var1变量的地址。 由于它可以与指针一起在任何地方使用,因此需要使用另一个变量的地址初始化指针

2)解除引用运算符(*) (2 ) The Dereference Operator (*))

It is used for two purposes with the pointers 1) to declare a pointer, and 2) get the value of a variable using a pointer.

它用于指针的两个目的:1) 声明一个指针 ,2) 使用指针获取变量的值

Read more: Accessing the value of a variable using pointer in C

阅读更多: 使用C语言中的指针访问变量的值

Example:

例:

#include <stdio.h>

int main(void)
{
	//normal variable
	int num = 100;      

	//pointer variable
	int *ptr;           

	//pointer initialization
	ptr = &num;         

	//printing the value
	printf("value of num = %d\n", *ptr);

	//printing the addresses
	printf("Address of num: %x\n", &num);
	printf("Address of ptr: %x\n", &ptr);

	return 0;
}

Output

输出量

value of num = 100
Address of num: 9505c134
Address of ptr: 9505c138


翻译自: https://www.includehelp.com/c/the-address-of-and-dereference-operators-with-the-pointers-in-c.aspx

取地址符和解引用符的区别

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值