Answer Posted / rajendra
#include <stdlib.h> /* EXIT_FAILURE, EXIT_SUCCESS */
#include <errno.h>
#include <stdio.h>
#define ROW 5
#define COL 5
int
main ( void )
{
int **cont_arr;
int **cont_arr;
int **arr = malloc ( ROW * sizeof ( int * ) );
if ( !arr )
{
perror ( "Error" );
exit ( EXIT_FAILURE );
}
for ( i=0; i < ROW; i++ )
{
arr[i] = malloc ( sizeof ( int ) * COL );
if ( !arr[i] )
{
perror ( "Error" );
exit ( EXIT_FAILURE );
}
}
/*
* Contiguous memory allocated for array.
Below.
*/
cont_arr = (int **) malloc ( ROW * sizeof ( int
* ) );
if ( !cont_arr )
{
perror ( "Error" );
exit ( EXIT_FAILURE );
}
cont_arr[0] = (int *) malloc ( ROW * COL *
sizeof ( int ) );
if ( !cont_arr[0] )
{
perror ( "Error" );
exit ( EXIT_FAILURE );
}
for ( int i=1; i < ROW; i++ )
cont_arr[i] = cont_arr[0] + i * COL;
exit ( EXIT_SUCCESS );
}
Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
Do character constants represent numerical values?
Can we declare variable anywhere in c?
what type of questions arrive in interview over c programming?
What is the easiest sorting method to use?
can any one tel me wt is the question pattern for NIC exam
What are keywords in c with examples?
What is a void pointer? When is a void pointer used?
Can you assign a different address to an array tag?
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above
What is header file in c?
What is c preprocessor mean?
Why do we use stdio h and conio h?
to find the closest pair
How will you divide two numbers in a MACRO?
What is scanf () in c?