Chapter 4 Pointer pointer (advanced) and Pointer (advanced)

Source: Internet
Author: User

Chapter 4 Pointer pointer (advanced) and Pointer (advanced)

Chapter 4 pointer (advanced)


So this course is to learn how to implement pointer and How to Use pointer.

We already know how to declare a pointer in the pseudo-code.

 

Integer myNum

RefToInteger myNumPtr

 

In C ++

Int myNum;

Int * myNumPtr;

 

Suppose X is any type.

Pseudo code: declare a pointer named ptr using refToX ptr

C ++: declare a pointer named ptr using X * ptr

 

It is worth noting that * this symbol is easy to mix.

 

Int myNum; // This declares an integer

Int * myNumPtr; // This declares a pointer to an integer

 

MyNum = 7;

MyNumPtr = & myNum; // This puts the address of myNum

Into the variable myNumPtr

 

This will happen in the memory.

Address Content

4683953 7 myNum

4683954 myNum

4683955 myNum

4683956 myNum

4683957 4683953 myNumPtr

4683958 myNumPtr

4683959 myNumPtr

4683960 myNumPtr

 

At this time, we declare an integer myNum as 7. At this time, we need a certain amount of memory space to store this integer. We all know that the integer size is 4.

However, the size of a pointer is also 4. Therefore, four Memory Spaces are allocated to the pointer during the Declaration. This memory space is the location pointed to by the pointer.

 

In the above example, the value stored by myNumPtr is the address, AKA, 4683953 of the value it points.

 

PS what we need to know is that the current computer memory is very large, so in the real situation, a pointer is adjacent to the value referred by this pointer is extremely rare.


This is very late, so write it here first. Continue tomorrow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.