C Programming Memory Allocation MCQ

21. Consider the following program, where are i, j and k are stored in memory?

#include <stdio.h>
#include <stdlib.h>
int i;
int main()
{
int j;
int *k = (int *) malloc (sizeof(int));
}

A. i, j and *k are stored in stack segment
B. i and j are stored in stack segment. *k is stored on heap.
C. i is stored in BSS part of data segment, j is stored in stack segment. *k is stored on heap.
D. j is stored in BSS part of data segment, i is stored in stack segment. *k is stored on heap.

View Answer


22. What function should be used to free the memory allocated by calloc() ?

A. dealloc();
B. malloc(variable_name, 0)
C. free();
D. memalloc(variable_name, 0)

View Answer


23. 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;
}

A. Error: in strcpy() statement
B. Error: in *ptr = (char)malloc(30);
C. Error: in free(ptr);
D. No Error

View Answer


24. Where does the uninitialized data gets stored in memory?

A. Code segment
B. Data segment
C. BSS- Block started by symbol
D. Heap

View Answer


25. malloc() returns a NULL if it fails to allocate the requested memory.

A. True
B. False

View Answer


26. If malloc() successfully allocates memory it returns the number of bytes it has allocated.

A. True
B. False

View Answer


27. Can I increase the size of dynamically allocated array?

A. Yes
B. No

View Answer


28. Can we increase the size of statically allocated array?

A. Yes
B. No

View Answer


29. When we dynamically allocate memory is there any way to free memory during run time?

A. Yes
B. No

View Answer


30. What is the output of this program?

#include <stdio.h>
#include<stdlib.h>
int main()
{
struct test
{
int i;
float f;
char c;
};
struct test *ptr;
ptr = (struct test *)malloc(sizeof(struct test));
ptr ->f = 5.5f;
printf("%f", ptr->f);
return 0;
}

A. 5.5
B. 5
C. 5.500000
D. 0.000000

View Answer







Also check :


Discussion


* You must be logged in to add comment.