Interview Questions and Answers :: Citrix
Home > Experience Archives > Citrix > Interview Question Set > Discussion
19. Write a code to implement 2D array dynamically in C? Get the number of rows and columns from the user.
Answer:
#include
#include
int main()
{
int row, col,i;
int **arr ;
printf ("Enter Row and Column\n");
scanf("%d %d",&row,&col );
printf("%d %d\n",row,col );
**arr = (int **) malloc (sizeof (int)*row);
for (i = 0; i < row; i++)
{
arr[i] = (int *) malloc(sizeof(int)*col);
}
return 0;
}
Ram
8 Apr, 2018 5:31 PM
#include
#include
int main()
{
int row, col,i;
int **arr ;
printf ("Enter Row and Column\n");
scanf("%d %d",&row,&col );
printf("%d %d\n",row,col );
**arr = (int **) malloc (sizeof (int)*row);
for (i = 0; i < row; i++)
{
arr[i] = (int *) malloc(sizeof(int)*col);
}
return 0;
}
#include
int main()
{
int row, col,i;
int **arr ;
printf ("Enter Row and Column\n");
scanf("%d %d",&row,&col );
printf("%d %d\n",row,col );
**arr = (int **) malloc (sizeof (int)*row);
for (i = 0; i < row; i++)
{
arr[i] = (int *) malloc(sizeof(int)*col);
}
return 0;
}
Report Error
Report Error
Please Login First Click Here