c语言指针访问 静态变量
As we know that a pointer is a special type of variable that is used to store the memory address of another variable. A normal variable contains the value of any type like int, char, float etc, while a pointer variable contains the memory address of another variable.
众所周知,指针是一种特殊类型的变量,用于存储另一个变量的内存地址。 普通变量包含int , char , float等任何类型的值,而指针变量包含另一个变量的内存地址。
Here, we are going to learn how can we access the value of another variable using the pointer variable?
在这里,我们将学习如何使用指针变量访问另一个变量的值 ?
Steps:
脚步:
Declare a normal variable, assign the value
声明一个普通变量,赋值
Declare a pointer variable with the same type as the normal variable
声明与普通变量相同类型的指针变量
Initialize the pointer variable with the address of normal variable
用普通变量的地址初始化指针变量
Access the value of the variable by using asterisk (*) - it is known as dereference operator
通过使用星号( * )访问变量的值-这称为解引用运算符
Example:
例:
Here, we have declared a normal integer variable num and pointer variable ptr, ptr is being initialized with the address of num and finally getting the value of num using pointer variable ptr.
在这里,我们已经声明了一个普通的整数变量num和指针变量PTR,PTR正在与NUM的地址,并终于得到使用指针变量PTR num的值初始化。
#include <stdio.h>
int main(void)
{
//normal variable
int num = 100;
//pointer variable
int *ptr;
//pointer initialization
ptr = #
//pritning the value
printf("value of num = %d\n", *ptr);
return 0;
}
Output
输出量
value of num = 100
翻译自: https://www.includehelp.com/c/accessing-the-value-of-a-variable-using-pointer-in-c.aspx
c语言指针访问 静态变量