promotion image of download ymail app
CCH asked in 電腦與網際網路程式設計 · 1 decade ago


1.what significant justification is there for the -> operator in c and c++?

2.multidimensional array can be stored in row major order, as in c++,or in column major order,as in Fortran.develop the access functions for both of these arrangements for three-dimensional arrays.

3.write a short discussion of what was lost and what was gained in java's designer' decision to not include the pointers of c++.

4.write a c program that does a large number of references to elements of two-dimensioned array,using only subscripting.write a second program that does the same operations but uses pointers and pointer and pointer arithmetic for the storage mapping function to do the array the time efficiency of the two programs.which of the two programs is likely to be more reliable? why?


sorry 可以用中文回答嗎?

Update 2:


Update 3:

Q5:Rewrite assignment1 with Java. Use Java's built-in class "vector" to implement

a heap-dynamic array in your program.

1 Answer

  • Inunu
    Lv 5
    1 decade ago
    Favorite Answer

    1. In C it simply means the value at where the pointer points to. In C++ there is a possibility to override and hence may exhibit a completely different behaviour.

    For instance in Visual C/C++ 2005 objects created with gcnew have '^' pointer which actually points to a meta structure containing pointer to actual object and extra information that can be used in profiling and clean up. It overrides '->' operator so you get the actual object instead of the meta structure.


    Suppose we have an array and a pointer:


    *ptr = &arr[0][0][0];

    Row first: arr[x][y][z] = ptr[(((x * q) + y) * r) + z]

    Column first: arr[x][y][z] = ptr[(((z * q) + y) * r) + x]

    (I.e. changing {x,y,z} to {z,y,x}.)



    * Requires a common base class acting as void* for arbitrary object

    * A new array needs to be created in order to generate a subset of array (i.e. substring)


    * Type information is preserved and can validate runtime type cast.

    * Arrays have size, which enables runtime index out-of-bound check.

    * Avoids the "ownership" problem with pointers (i.e. who does the free up / clean up?)


    int TableA[1024][1024];

    void initA()


    memset(&TableA[0], 0, sizeof(int) * 1024 * 1024);


    int TableBData[1024 * 1024];

    int *TableB[1024];

    void initB()


    int i;

    memset(&TableBData[0], 0, sizeof(int) * 1024 * 1024);

    for(i = 0; i < 1024; i++)


    TableB[i] = &TableBData[i * 1024];



    Using TableA is more likely to be more reliably. Using TableB you must ensure this array of pointers are set with correct addresses, which is a potential source of error.

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.