Level 1 and level 2 pointers in C Language

Source: Internet
Author: User

Level 1 and level 2 pointers in C Language

Pointer Concept

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

The pointer is the address, so when using it, it is often said that the pointer variable is a pointer

The pointer variable is the variable that stores the address.

Int * p1; // a variable is applied for, that is, a memory is opened in the memory to store data.

// Eight bytes are opened, and the pointer occupies 8 bytes in Mac.

The pointer should be used as a pointer variable.

1> arithmetic operations

+ How many bytes does 1 move?

Type: int *, long *, char *

2> get the address data

The pointer stores the address to retrieve the data from the address.

Addressing operator * & p1-> p1

3> modify the data in the address

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

If it is not a pointer variable, but a common variable, it is a value transfer: the function is two different variables, but the stored data is the same (like sending a file)

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

Since function parameters can be modified using pointers, which affects the variables outside the function, function parameters are usually set to pointer-type variables.

Functions that return multiple data using parameters

Scanf ("% d", & num );

Level 2 pointer

The second-level pointer is the pointer to the first-level pointer (n-level pointer is the pointer to the n-1-level pointer)

The essence of a pointer is an address, so several levels of pointers are just an address. The only difference is the addressing result (* p)

1> in development, the second-level pointer is used to return a first-level pointer data using a function or method.

2> if you need to use function parameters to return data, if the returned data is normal, pass the first-level pointer

3> If a level-1 pointer is returned, the parameter should be a level-2 pointer.

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

* P1 refers to the num value, * p2 refers to the p1 memory address, and ** p2 also refers to the num value ......

 

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.