C Language > Pointers

Source: Internet
Author: User

C language arrays and pointers

Const

There are some rules to note about pointers and Const. First, it is legal to initialize the address of the const data or non-const data to a pointer to a const or to assign a value to it.

However, you can only assign addresses of non-const data to normal pointers. (That is, a const value cannot be assigned to a normal pointer);

Pointers and multidimensional arrays:

Zippo = &zippo[0];

zippo+2 = = &zippo[2];

* (zippo+2) = = &zippo[2][0];

* (zippo+2) + 1 = = &zippo[2][1];

* (* (zippo+2) + 1) = = Zippo[2][1];

Pointer to multidimensional array:

Int (* PZ) [2]; >> PZ points to an array containing two int types;

( such as: zippo[4][2];)

INT * Pax[2]; >> Pax is an array of two pointer elements, each of which points to an int pointer;

( just like the meaning of the array, it declares two pointers, one is pax[0] and the other is pax[1])

(such as pax [0] = Zippo; pax[1] = ZIPPP; >> *pax[0] = = *pax[1];)

An array variable is a const pointer, so it cannot be assigned a value:

int a[] <==> int * Const A = ....

The array variable itself expresses the address, so:

int a[10]; int * p = A; No need to take & address

But the cell expression of an array is a variable, it needs to use & address

A = = &a[0]

The [] operator can do the array, or it can do the pointer:

P[0] <==> a[0];

* the operator can do the pointer, or it can do the array:

*a = 25;

C Language > Pointers

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.