What will be the output of the following code −
#include
#include
int main() {
union my_union {
int i;
float f;
char c;
};
union my_union* u;
u = (union my_union*)malloc(sizeof(union my_union));
u->f = 20.60f;
prin
Answer: B
Using unions, we can use same memory location to hold multiple type of data. All member of union uses same memory location which has maximum space. Here float is used, which has 20.60f = 20.600000.
Enter details here
Which of the following is true?
Answer: B
The name malloc and calloc() are library functions that allocate memory dynamically. It means that memory is allocated during runtime(execution of the program) from heap segment.
Enter details here
Which function is used to delete the allocated memory space?
Answer: B
free() is used to free the memory spaces allocated by malloc() and calloc().
Enter details here
What is the output of this program?
#include
#include
int main()
{
int i;
char *ptr;
char *fun();
ptr = fun();
printf(" %s", ptr);
return 0;
}
char *fun()
{
char disk[30];
strcpy(disk, "letsfindcourse");
printf("%s ",disk);
return disk;
}
Answer: A
Here disk is an auto array, when array is used as return value, it will die when the control go back to main() function of a program. Thus memory in c alone prints.
Enter details here
malloc() allocates memory from the heap and not from the stack.
Answer: A
No answer description available for this question
Enter details here
Which of the following statement is correct prototype of the malloc() function in c ?
Answer: D
No answer description available for this question
Enter details here
The function ____ obtains block of memory dynamically.
Answer: C
None
Enter details here
Which languages necessarily need heap allocation in the run time environment?
Answer: D
Heap allocation is needed for dynamic data structures like tree, linked list, etc.
Enter details here
How will you free the memory allocated by the following program?
#include
#include
#define MAXROW 3
#define MAXCOL 4
int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}
Answer: D
No answer description available for this question
Enter details here
Output?
# include
# include
void fun(int *a)
{
a = (int*)malloc(sizeof(int));
}
int main()
{
int *p;
fun(p);
*p = 6;
printf("%dn",*p);
return(0);
}
Answer: A
No answer description available for this question.
Enter details here