Zoho Dynamic memory allocation Quiz 1

Question 1

Time: 00:00:00

Which header file should be included to use functions like malloc() and calloc()?

stdlib.h

stdlib.h

string.h

string.h

dos.h

dos.h

memory.h

memory.h

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
What function should be used to free the memory allocated by calloc() ?

dealloc();

dealloc();

malloc(variable_name, 0)

malloc(variable_name, 0)

free();

free();

memalloc(variable_name, 0)

memalloc(variable_name, 0)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
How will you free the memory allocated by the following program?

#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4

int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}

memfree(int p);

memfree(int p);

dealloc(p);

dealloc(p);

malloc(p, 0);

malloc(p, 0);

free(p);

free(p);

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
Specify the 2 library functions to dynamically allocate memory?

malloc() and memalloc()

malloc() and memalloc()

alloc() and memalloc()

alloc() and memalloc()

malloc() and calloc()

malloc() and calloc()

memalloc() and faralloc()

memalloc() and faralloc()

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
Point out the error in the following program.

#include<stdio.h>
#include<stdlib.h>

int main()
{
int *a[3];
a = (int*) malloc(sizeof(int)*3);
free(a);
return 0;
}

Error: unable to allocate memory

Error: unable to allocate memory

Error: We cannot store address of allocated memory in a

Error: We cannot store address of allocated memory in a

Error: unable to free memory

Error: unable to free memory

No error

No error

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
Point out the error in the following program.

#include<stdio.h>
#include<stdlib.h>

int main()
{
char *ptr;
*ptr = (char)malloc(30);
strcpy(ptr, "RAM");
printf("%s", ptr);
free(ptr);
return 0;
}

Error: in *ptr = (char)malloc(30);

Error: in *ptr = (char)malloc(30);

Error: in strcpy() statement

Error: in strcpy() statement

Error: in free(ptr);

Error: in free(ptr);

No error

No error

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
Which of the following statement is correct prototype of the malloc() function in c ?

int* malloc(int);

int* malloc(int);

char* malloc(char);

char* malloc(char);

unsigned int* malloc(unsigned int);

unsigned int* malloc(unsigned int);

void* malloc(size_t);

void* malloc(size_t);

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
Point out the correct statement which correctly free the memory pointed to by 's' and 'p' in the following program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
struct ex
{
int i;
float j;
char *s
};
struct ex *p;
p = (struct ex *)malloc(sizeof(struct ex));
p->s = (char*)malloc(20);
return 0;
}

free(p); , free(p->s);

free(p); , free(p->s);

free(p->s); , free(p);

free(p->s); , free(p);

free(p->s);

free(p->s);

free(p);

free(p);

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
Point out the correct statement which correctly allocates memory dynamically for 2D array following program?

#include<stdio.h>
#include<stdlib.h>

int main()
{
int *p, i, j;
/* Add statement here */
for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
{
p[i*4+j] = i;
printf("%d", p[i*4+j]);}}
return 0;
}

int* malloc(int);

int* malloc(int);

char* malloc(char);

char* malloc(char);

unsigned int* malloc(unsigned int);

unsigned int* malloc(unsigned int);

void* malloc(size_t)

void* malloc(size_t)

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
Point out the correct statement which correctly allocates memory dynamically for 2D array following program?

#include<stdio.h>
#include<stdlib.h>

int main(){
int *p, i, j;
/* Add statement here */
for(i=0; i<3; i++)
{
for(j=0; j<4; j++)
{
p[i*4+j] = i;
printf("%d", p[i*4+j]);
}
}
return 0;}

p = (int*) malloc(3, 4);

p = (int*) malloc(3, 4);

p = (int*) malloc(3*sizeof(int));

p = (int*) malloc(3*sizeof(int));

p = malloc(3*4*sizeof(int));

p = malloc(3*4*sizeof(int));

p = (int*) malloc(3*4*sizeof(int));

p = (int*) malloc(3*4*sizeof(int));

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice!","Keep trying!","Not bad!","Good work!","Perfect!"]

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Completed

0/0

Accuracy

0%