Similarities and differences between java and c ++ arrays: supplemental

First thing to remember: The Java arrays are objects. In other words, you can not declare an array, you can only declare a pointer. The pointer to an object that represents an array.

Java code the following statement:

int  students[];

The equivalent of C ++ code:

 

That declares a pointer to a pointer to an array object, array elements to int.

Array which is user-defined types, the template parameter represents the element type:

 

Array elements can be int:

 

It may be a pointer to the object:

 

It may also be points to another array of pointers to objects

 

 

 

 

These C ++ code, there is a more concise written in Java, as follows:

 

Or in the form:

int  students1[];

Student  students2[];

int  students[][];

Student  students4[][];

When you declare a pointer to an array object, regardless of the number of elements in the array may include (even if designated, is also deaf ears), but really is an array, you must specify the number of elements:

 

This is equivalent in C ++

 

When it was declared not need to specify the number of elements:

 

Real time generated need to specify the number of elements:

 

Why do we use C ++ to above when interpreted Java code, using the user-defined class Array? C ++ is not itself an array it?

C ++ array itself, create a statement with inseparable - that is created when a statement.

 

Unless it is done function parameter

 

At this time, the number of elements with no write to write a kind

 

But such an approach in fact, such an approach below

 

That is not true type students7 pointer to an array (in Java, write students7 is a pointer to an array), but a pointer to the first element of the array. Array C ++ with Java array looks exactly the same, but in fact, a big difference.

I think C ++ inherited from C language historical burden - a pointer to the first element of the array of point representatives pointer to an entire array of practice, really lowB home. As a point to the first node of the linked list pointer representative of the entire list data structure as lowB.

lowB:low  Byte

About C language array with a pointer pointing to the first element of the array of relationships: the concept of decay

Guess you like

Origin www.cnblogs.com/dr-xsh/p/12511881.html