0

i found following code to create a two dimensional array at run time if one of the dimension is known..

char (*c)[5];
c=new char[n][5];

first line is pointer to an array of 5 integers but i couldnt undesratnd the second step.

2
Contributors
1
Reply
10
Views
2 Years
Discussion Span
Last Post by Ancient Dragon
0

first line is pointer to an array of 5 integers

Those are char pointers, not integers.

The first line declares an array of unknown number of pointers, each pointer points to a memory block of 5 bytes.

The second line allocates a single block of memory with size n*5. This is much faster and more efficient than allocating each of the n pointers individually.

Edited by Ancient Dragon

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.