Simple example of C language pointer

Pointer, defined in the Chinese dictionary as: (1) the needle indicating the time on a clock;

In the field of computer science, the definition of a pointer is as follows: In a high-level language, an address is aptly called a pointer. The address means that the system allocates the address of the first byte unit of the storage space for the variable in the memory, which is called the address of the variable. The address is used to identify each storage unit, which is convenient for users to correctly access the data in the storage unit.

one picture

 

The simple code implementation is as follows

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a=100;
	cout<<"这是a的值:"<<a<<endl; 
	cout<<"这是a的地址&a:"<<&a<<endl; 
	int *p= &a;
	cout<<"这是指向a的指针p的指针域*p(=a的值):"<<*p<<endl; 
	cout<<"这是指向a的指针p的值p(=a的地址):"<<p<<endl; 
	cout<<"这是指向a的指针p的地址&p(p也需要在存储区开辟空间和声明地址):"<<&p<<endl; 
	int* *q= &p;
	cout<<"这是指向指针p的指针q的指针域*q(也就是p的本身的值也就是a的地址):"<<*q<<endl; 
	cout<<"这是指向指针p的指针q的值q(=p的地址):"<<q<<endl; 
	cout<<"这是指向指针p的指针q的地址&q(q也需要在存储区开辟空间和声明地址):"<<&q<<endl; 
}

The result of the operation is as follows

 

Guess you like

Origin blog.csdn.net/wjqsm/article/details/128466630