C-language level pointers and level two pointers

Source: Internet
Author: User

The concept of pointers

The pointer is the address that can be used to find the specified data.

The pointer is the address, so when used, it is often simple to say that the pointer variable is a pointer

A pointer variable is a variable that stores an address

int *p1;//applies a variable that opens up a piece of memory in memory, storing the data

Opens up 8 bytes, and the pointer is 8 bytes under the Mac

Using pointers, you should actually say, using pointer variables

1> arithmetic operations

+1 move a few bytes?

See type: INT *, long *, char *

2> get the data represented by the address

The address is stored in the pointer, you can remove the data from the address

Addressing operator *&p1-P1

3> changing the data in the address

4> use as Function parameters (* * * * *)

If the pass is not a pointer variable, but a normal variable, is the value of the pass: inside the function and outside the function is two different variables, just the same data stored (like sending a file)

If a pointer variable is passed, that is, the address is passed, then the reference is passed: inside and outside the function can be considered the same variable (like sending a link)

Since the function parameters use pointers, it is possible to implement variables within the function that affect variables outside the function after they have been modified. Therefore, the function parameter is often set to a variable of pointer type

Implementing functions that return multiple data using parameters

scanf ("%d", &num);

Second-level pointers

A secondary pointer is a pointer to a first-level pointer (an n-level pointer is a pointer to a n-1-level pointer)

The essence of the pointer is the address, then the few pointers are just an address, the only difference is the result of addressing (*P)

1> the use of level two pointers in development is to return a first-level pointer data using a function or method

2> If you need to return data with a function parameter, if you return a generic data, pass a first-level pointer

3> if a first-level pointer is returned, then the parameter should be a level two pointer

4> If the return is an n-level pointer, then the parameter should be a n+1-level pointer

*P1 refers to the value of NUM, *P2 refers to the address of P1 memory, **P2 also refers to the value of num ...

C-language level pointers and level two pointers

Related Article

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.