[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Cisco

10. How will you allocate a memory to 2d integer array ??

Answer:

#include
Void main() {
int **array;
array = (int **)malloc(nrows * sizeof(int *));
if(array == NULL)
{
fprintf(stderr, "out of memory\n");
return;
}
for(i = 0; i < nrows; i++)
{
array[i] = (int *)malloc(ncolumns * sizeof(int));
if(array[i] == NULL)
{
fprintf(stderr, "out of memory\n");
return;
}
}
for(i = 0; i < nrows; i++)
free(array[i]);
free(array);
}

Post Your Answer Here:      Public      Private

Rate This: +0 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here