Join Examsbook
842 0

Q: How would you dynamically allocate a 2-D array of integers?

  • Show AnswerHide Answer
  • Workspace

Answer :
Explanation :

#include "alloc.h" #define MAXROW 3 #define MAXcol 4 main() {         int *p, i, J;         p = (int *) malloc (MAXROW * MAXCOL * sizeof (int));          for ( i=0; i < MaxROW ; i++)          {                 for (j=0; j < MAXCOL ; j++)                 {                        p [ i * MAXCOL + j] = i;                        printf ( "%d", p [i * MAXCOL + j] );                  }                   printf ("\n");           } }

Are you sure

  Report Error

Please Enter Message
Error Reported Successfully