Pointer array and array pointer

Source: Internet
Author: User

When an array is passed into a function, it degrades to a pointer. A one-dimensional array is directly degraded into a pointer, and a two-dimensional array is degraded into a pointer pointing to a one-dimensional array, such as char (*) [32] (optional): char a [] []; func (char B [], int rows, int cols); func (char (* B) []); pointer array: array of pointers, which is an array used to store pointers, that is, the array elements are pointer array pointers: a pointer to an array, that is, the pointer to the array int (* p) [10]; defines an array pointer, this pointer is no different from a general pointer. It only points to an array. Here we take the array as the basic element for processing. That is to say, the entire array is taken as a type, and the array name is a specific variable of this type. For example: int a [10]; an array type in the shape of int [10]; a is a newly defined variable. For the array type: int [10], we can define a pointer, int (* p) [10]. Note that a small Arc must be added here. Otherwise it will become a pointer array. After a pointer is defined, we can assign a value to the pointer, for example, p = & a; if a two-dimensional array is defined, int c [3] [10]. We can think that a one-dimensional array is defined. This array has three int [10] elements. Therefore, like an ordinary array, we can assign the array name to the pointer, which is actually the address of the first element to the pointer. That is, p = c; or p = & c [0]. And so on.

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.