Arrays and pointers in C ++

Source: Internet
Author: User
The array and pointer in C ++ first look at two definitions (Declaration) int * aryp [10]; int (* pary) [10]; aryp is an array of 10 elements, the element type in the array is int * pary, which is a pointer to the array, the type of the specified array is int [10]. In this case, the Pary definition will clear a bit of typdef int int_ary_ten [10]; int_ary_ten * pary; c ++ is a strong type (strong typed) language. c ++ has a special set of types: the type of the array is not only related to the element type, it is also related to the number of elements. Int Aten [10]; int anine [9]; then the Aten type is different from the anine type. The Aten type is int [10], the anine type is int [9] instead of the int * const, although we can use it as an int * Const. This is different from Java. in Java, the two types are array arrays. They cannot be used as function parameters or return value types void Foo (INT Arg [10]). {} The ARG type is actually int * const, and it has nothing to do with that 10. It doesn't even matter if you don't write anything in. This is why some people say that the array name is a constant pointer. In addition to functions, arrays cannot be used as the typeid parameter typeid (Aten ). name () returns "int *". For this reason, typeid (Aten) = typeid (anine) returns trueaten. When anine is passed in, the type is changed to int * const (typeid does not record constant information, so cosnt is removed). Since the array is also a type, the * operator can define another type: pointer to the array. For example, the starting pary can define int (* pary) [10] = & Aten; and INT (* pary) [10] = & anine; is invalid. The compiler complained: cannot convert from 'int (*) [9] 'to 'int (*) [10]'

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.