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
Explain how can you restore a redirected standard stream?
What is the use of the function in c?
Write a program to find factorial of a number using recursive function.
write a program to concatenation the string using switch case?
What is extern variable in c with example?
How will you declare an array of three function pointers where each function receives two ints and returns a float?
List a few unconditional control statement in c.
What does the characters “r” and “w” mean when writing programs that will make use of files?
What happens if you free a pointer twice?
If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?
Is it possible to initialize a variable at the time it was declared?
What is a node in c?
Explain how are 16- and 32-bit numbers stored?
`write a program to display the recomended action depends on a color of trafic light using nested if statments
if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above