#include <cstdlib>
#include <iostream>

static void fillArray(int **array);

int main() {
    //allocating a 2D array
    int **array;
    array=new int*[10];
    for(int i=0;i<10;i++)
        *(array+i)=new int[5];
    //sending this array to a function
    fillArray(array);
    for(int i=0;i<10;i++)
        for(int j=0;j++;j<5)
            std::cout<<array[i][j];
    for(int x=0;x<10;x++)
        delete[] array[x];
    delete[] array;
    return 0;
}

static void fillArray(int **array) {
    int x=0;
    for(int i=0;i<10;i++)
        for(int j=0;j<5;j++) {
            array[i][j]=x;
            x++;
        }
}

compiles, but does nothing.

Recommended Answers

All 2 Replies

line 16 is for(int j=0;j++;j<5) , it should be for(int j=0;j<5;j++) (the j++ and the j < 5 are swapped around).

Use unsigned int instead of int.

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.