当前位置:网站首页>Now you must know the pointer

Now you must know the pointer

2022-06-12 13:47:00 Disobey the law

Don't want to learn , Don't want to push mathematical formulas , So let's look at the pointer again , This time it seems that I really understand !!
If there is any problem, please d I , I'll change it right away !! Help every dream

If you talk about the pointer again, you will crack

& It's an address character ,& The variable represents the address of the variable
* Pointer name It refers to the content of the space corresponding to this pointer / The space corresponding to the pointer
&(* Pointer name ) It refers to the address of the space corresponding to this pointer
Pointer name and &(* Pointer name ) The effect is the same , Is the pointer to the address of that space

The address of a pointer itself ( Space for storing pointers ) The pointer is defined the moment it is created , Do not modify .
But the pointer to space can be modified .

	int k = 2;
	int* a = new int();
	//*a Is the newly allocated space 

	cout << &k << endl;
	cout << &a << endl;
	cout << &(*a) << endl;
	cout << a << endl;
	//&a Is a pointer a The address of ,&k yes int type k The address of , Defining variables automatically assigns addresses to variables 
	// &(*a) Is the address of the space pointed to by the pointer , therefore p=p->next Is to modify p Pointer pointing 
	// The above three addresses are different , The last two are the same 

	a = new int();
	cout << &(*a) << endl;
	// here &(*a) With no reallocation of space &(*a) Dissimilarity , current &(*a) Is the newly allocated space , That is, the space to which the pointer points again 

 Insert picture description here
Take a look at the picture
 Insert picture description here

Add a little more

&b: refer to b The address of ,
&&b : Store b The address of
*b : take b Value pointing to space .

(*p).name and p->name Same ,*p Is the space pointed to by the pointer ,.a This is the space a Elements .p->name Namely p In this space a Elements .

原网站

版权声明
本文为[Disobey the law]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010515285627.html