Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Language%20in%20C%20Interview%20Questions%20and%20Answers

Question: Allocating memory for a 3-D array

#include "alloc.h"
#define MAXX 3
#define MAXY 4
#define MAXZ 5
main( )
{
int ***p, i, j, k ;
p = ( int *** ) malloc ( MAXX * sizeof ( int ** ) ) ;
for ( i = 0 ; i < MAXX ; i++ )
{
p[i] = ( int ** ) malloc ( MAXY * sizeof ( int * ) ) ;
for ( j = 0 ; j < MAXY ; j++ )
p[i][j] = ( int * ) malloc ( MAXZ * sizeof ( int ) ) ;
}
for ( k = 0 ; k < MAXZ ; k++ )
{
for ( i = 0 ; i < MAXX ; i++ )
{
for ( j = 0 ; j < MAXY ; j++ )
{
p[i][j][k] = i + j + k ;
printf ( "%d ", p[i][j][k] ) ;
}
printf ( "n" ) ;
}
printf ( "nn" ) ;
}
}
Data Structures
How to distinguish between a binary tree and a tree?

Answer: A node in a tree can have any number of branches. While a binary tree is a tree structure in which any node can have at most two branches. For binary trees we distinguish between the subtree on the left and subtree on the right, whereas for trees the order of the subtrees is irrelevant.
Consider the following figure...

This above figure shows two binary trees, but these binary trees are different. The first has an empty right subtree while the second has an empty left subtree. If the above are regarded as trees (not the binary trees), then they are same despite the fact that they are drawn differently. Also, an empty binary tree can exist, but there is no tree having zero nodes.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook