May 2012
Intermediate to advanced
679 pages
16h 56m
English
Earlier we have seen pointers and arrays working hand in hand. This is true for two dimensional arrays too. As we are using pointers, we will like to allocate memory dynamically. We know that C++ has introduced operator new. Hence, we will stick2 to this operator. There are two distinct strategies for allocation memory in this case. We will discuss them as separate methods.
Study the following declaration:
int *p[M]
As precedence of operator [] is higher than ‘*’, variable p becomes an array of M elements. (In this section, M will be synonym with number of rows and N with number of columns.) See Figure 12.3.
Each element like p[0] or p[1] is a pointer to integer. A pointer to integer can be ...
Read now
Unlock full access