Question 1
X: m=malloc(5); m= NULL; 1: using dangling pointers Y: free(n); n->value=5; 2: using uninitialized pointers Z: char *p; *p = ’a’; 3. lost memory is:
Question 2
[PI] int * g (void)
{
int x= 10;
return (&x);
}
[P2] int * g (void)
{
int * px;
*px= 10;
return px;
}
[P3] int *g (void)
{
int *px;
px = (int *) malloc (sizeof(int));
*px= 10;
return px;
}
Question 3
Output?
# include<stdio.h>
# include<stdlib.h>
void fun(int *a)
{
a = (int*)malloc(sizeof(int));
}
int main()
{
int *p;
fun(p);
*p = 6;
printf("%d",*p);
return(0);
}
May not work
Works and prints 6
Question 4
Which of the following is/are true
calloc() allocates the memory and also initializes the allocates memory to zero, while memory allocated using malloc() has random data.
calloc() takes two arguments, but malloc takes only 1 argument.
Both malloc() and calloc() return \'void *\' pointer.
All of the above
Question 5
Question 6
"ptr = calloc(m, n)" is equivalent to following
ptr = malloc(m * n);
"ptr = calloc(m, n)" is equivalent to following
ptr = malloc(m * n);
memset(ptr, 0, m * n);
"ptr = calloc(m, n)" is equivalent to following
ptr = malloc(m);
memset(ptr, 0, m);
"ptr = calloc(m, n)" is equivalent to following
ptr = malloc(n);
memset(ptr, 0, n);
Question 7
#include<stdio.h>
int main()
{
int *p = (int *)malloc(sizeof(int));
p = NULL;
free(p);
}
Question 8
int i;
int main()
{
int j;
int *k = (int *) malloc (sizeof(int));
}
Question 9
Which languages necessarily need heap allocation in the run time environment?
Those that support recursion
Those that use dynamic scoping
Those that use global variables
Those that allow dynamic data structures
Question 10
There are 10 questions to complete.