取地址符和解引用符的区别_(&)和解引用(*)运算符的地址以及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 variableint num = 100; //pointer variableint *ptr; //pointer initializationptr = # //printing the valueprintf("value of num = %d\n", *ptr);//printing the addressesprintf("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
取地址符和解引用符的區別
總結
以上是生活随笔為你收集整理的取地址符和解引用符的区别_(&)和解引用(*)运算符的地址以及C中的指针...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果越狱多少钱啊?
- 下一篇: 一个假紫重甲护肩和一个假紫短剑合成会出来