dynamically allocates 2 dimensional array

Implement a function foo that dynamically allocates a 2 dimensional array of integers and returns it. The signature of the function is as under -
int **foo(int rows, int columns)

Comments

  1. return type of functn shd be int**..
    plz correct me if m wrong

    ReplyDelete
  2. @divya i am sorry it should be int**

    ReplyDelete
  3. int foo(int rows,int columns){
    int **a;
    a = (int **)malloc(rows*sizeof((int *));
    for(int i = 0;i<rows;i++)
    a[i] = (int *)malloc((columns)*(sizeof(int));
    return a;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog