C language level pointers and level two pointers in detail _c language

Source: Internet
Author: User

The concept of pointers

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

Pointers are addresses, so when used, it's often easy to say pointer variables are pointers

A pointer variable is a variable that stores an address

int *p1;//applies a variable that opens up a chunk of memory in memory and stores the data

Opens up 8 bytes, and the pointer takes up 8 bytes under the Mac.

Using pointers, it should actually be said to use pointer variables

1> arithmetic Operations

+1 move a few bytes?

See type: INT *, long *, char *

2> Get the data that the address represents

The address is stored in the pointer so that the data in that address can be removed

Addressing operators *&p1-> p1

3> Modify the data in the change address

Use of 4> as a function parameter (* *)

If the pass is not a pointer variable, but a normal variable, that is, the value is passed: Within the function and the function is two different variables, but only stored the same data (like sending files)

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

Because the function parameter uses the pointer, can realize the function inside the variable modification, affects the variable outside the function. Therefore, the function argument is often set to a variable of the pointer type

To implement a function that returns multiple data using a parameter

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 nature of the pointer is the address, then a few pointers are only one address, the only difference is the result of addressing (*P)

The place where 1> uses a level two pointer in development is to use a function or method to return a first-level pointer data

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

3> If you return a first-level pointer, then the argument should be a two-level pointer

4> if a n-level pointer is returned, then the argument should be a n+1 level pointer

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

Thank you for reading, I hope to help you, thank you for your support for this site!

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.