How will you free the memory allocated by the following program?
#include
#include
#define MAXROW 2
#define MAXCOL 3
int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}
Answer: D
Dynamically allocated memory created with either calloc() or malloc() doesn't get freed on their own. You must explicitly use free() to release the space.
Enter details here
malloc() returns a float pointer if memory is allocated for storing float's and a double pointer if memory is allocated for storing double's.
Answer: B
No answer description available for this question
Enter details here
When we dynamically allocate memory is there any way to free memory during run time?
Answer: A
there any way to free memory during run time by Using free().
Enter details here
What is the output of this program?
#include
#include
int main()
{
struct test
{
int i;
float f;
char c;
};
struct test *ptr;
ptr = (struct test *)malloc(sizeof(struct test));
ptr ->f = 2.5f;
printf("%f", ptr->f);
return 0;
}
Answer: B
Here test is a structure name which consist of three variables of three different data types. ptr is the pointer variable, for which the memory is allocated dynamically by using malloc() of function and then it is pointed towards the structure floating variable f. Now f is initialized with a value 2.5f and then outputted as 2.500000.
Enter details here
Which of the following statement is true?
Answer: B
At first, it creates the preprocessed code, in that phase, it attaches the codes present in file mentioned in #include statements into the code then sent to the compiler.
Enter details here
The most appropriate matching for the following pairs
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:
Answer: D
No answer description available for this question.
Enter details here
The advantage of using linked lists over arrays is that ________
Answer: B
Insertion and deletion in a linked list can be done at any position. On the other hand, in an array, to insert an element at a specific position, the rest of the elements have to be moved one position to the left and to delete an element, all the elements after the deleted element have to be moved one position to the right.
Enter details here
The type of linked list in which the node does not contain any pointer or reference to the previous node is _____________
Answer: B
A singly linked list is one in which each node has two fields, namely data field and pointer field. Data field stores the data and the pointer field points to the address of the next node.
Enter details here
What is the output of this program?
#include
#include
int main()
{
int *j = (int*)malloc(4 * sizeof(int));
*j = 15;
free(j);
printf("%d", *j);
return 0;
}
Answer: B
In this program, a pointer variable *j is declared and its memory space is allocated using malloc() and then an integer value 15 is set to a pointer variable *j. Now free(j) is used to free or delete the memory space allocated to the pointer variable *j using malloc(). While freeing the memory space allocated using malloc(), all allocated space will be deleted and by default the deleted space will be denoted by some garbage value and is outputted.
Enter details here
During preprocessing, the code #include gets replaced by the contents of the file stdio.h. Which is true?
Answer: B
Preprocessing enlarges and boosts the C programming language by replacing preprocessing directive #include with the content of the file stdio.h.
Enter details here