how can I use it ?? and how can I allocate and intialize it ???

how can I use it ??

A "dynamic array" is really nothing more than simulating an array. Once created, you use it very much like a regular array.

how can I allocate and intialize it ???

This will allocate a dynamic array of 10 pointers to int, then initialize the pointers with an increasing value. The values are printed by iterating over the array and dereferencing each pointer. Finally, the dynamic array is freed:

// Allocate
int **a = new int*[10];

// Initialize
for (int i = 0; i < 10; i++)
{
    a[i] = new int(i);
}

// Use like an array
for (int i = 0; i < 10; i++)
{
    cout << *a[i] << '\n';
}

// Release
delete[] a;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.