41. The following C code is an example of . . . . . . . .
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
char *p,*q;
p=(char*)malloc(3*sizeof(char));
q=p;
strcpy(p,"hello");
printf("p=%s",p);
printf("q=%s",q);
free(q);
q=NULL;
gets(p);
gets(q);
printf("%s",p);
printf(“%s”,q);
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
char *p,*q;
p=(char*)malloc(3*sizeof(char));
q=p;
strcpy(p,"hello");
printf("p=%s",p);
printf("q=%s",q);
free(q);
q=NULL;
gets(p);
gets(q);
printf("%s",p);
printf(“%s”,q);
}
42. If malloc() and calloc() are not type casted, the default return type is . . . . . . . .
43. Which of the following functions allocates multiple blocks of memory, each block of the same size?
44. A condition where in memory is reserved dynamically but not accessible to any of the programs is called . . . . . . . .
45. Which of the following header files must necessarily be included to use dynamic memory allocation functions?
46. What will be the error (if any) in the following C code?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *p;
*p = (char)calloc(10);
strcpy(p, "HELLO");
printf("%s", p);
free(p);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *p;
*p = (char)calloc(10);
strcpy(p, "HELLO");
printf("%s", p);
free(p);
return 0;
}
47. What will happens if the statement free(a) is removed in the following C code?
#include<stdio.h>
#include<stdlib.h>
main()
{
int *a;
a=(int*)malloc(sizeof(int));
*a=100;
printf("*a%d",*a);
free(a);
a=(int*)malloc(sizeof(int));
*a=200;
printf("a%p",a);
*a=200;
printf("a%d",*a);
}
#include<stdio.h>
#include<stdlib.h>
main()
{
int *a;
a=(int*)malloc(sizeof(int));
*a=100;
printf("*a%d",*a);
free(a);
a=(int*)malloc(sizeof(int));
*a=200;
printf("a%p",a);
*a=200;
printf("a%d",*a);
}
48. In the function realloc(), if the new size of the memory block is larger than the old size, then the added memory . . . . . . . .
49. What will be the output of the following C code if it is executed on a 32 bit processor?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
p = (int *)malloc(20);
printf("%d\n", sizeof(p));
free(p);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
p = (int *)malloc(20);
printf("%d\n", sizeof(p));
free(p);
return 0;
}