Small words c pointer

Source: Internet
Author: User

Pointer C language, occupies an important position. Before the final int, char, double, other categories appear. It is a kind of data type, its special reason is int and other basic type variable store content, the PIN variable holds the address.

Memory is divided into a number of hope zones, where the cell number is the address and the pointer is defined as:

Data type * variable name.

Eg:int *pnum;

Of * Indicates that pnum is a pointer-type variable. int is the type of a pointer variable, which means it can only point to an int variable.

The pointer also has an operator of "&" named: Fetch address character. Hence the name of righteousness. Take the address, take the address where the variable is located.

such as: int a = 0. PN;

PN = &a;

It is now possible to manipulate variable a indirectly through the pointer pn.

So how can we manipulate the value of a? You need to use the value of the "*", where the * is different from the above * meaning, the above * indicates that this is a pointer variable, and here * represents the value of the variable that the pointer variable refers to.

such as: int A, b = 1,*pn;

PN = b;

A = *PN;

At this point A has a value of 1.

Pointers are also capable of self-increment or self-subtraction operations. Because the pointer holds the "Unit number" (address), when the pointer is added 1, it points to the next "unit number".

such as: int *pn;

int a[3] = {n/a};

PN = A;

pn++;

When array A is assigned directly to PN. The PN points to the address of the array's first address, which is a[0]. When pn++, PN points to the address of the next address, also known as a[1], and is self-reducing.

It's important to note that. When the pointer is to the last element of the array, since that is the case, then when the operation is added, the array is out of bounds. Because the address pointed to unknown, what happened in the end is unknown.

Small words c pointer

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.