Top

Memory Allocation

Answer: A

This function is used to flush output stream only. It clears the output buffer and send the output to the console.

Enter details here

52.

Point out the error of the following code −

#include 
#include 
#include 
int main() {
   char* ptr;
   *ptr = (int*)malloc(30);
   strcpy(ptr, "ABC");
   printf("%s", ptr);
   free(ptr);
}

 

Answer: B

Here this makes integer from pointer, without a cast

Enter details here

53.

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 = 5.5f;
 printf("%f", ptr->f);
 return 0;
}

 

Answer: C

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 5.5f and then outputted as 5.500000.

Enter details here

54.

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

Answer: B

No answer description available for this question.

Enter details here

55.

What will be the output of the program (16-bit platform)?

#include
#include

int main()
{
    int *p;
    p = (int *)malloc(20);
    printf("%d\n", sizeof(p));
    free(p);
    return 0;
}

 

Answer: B

No answer description available for this question

Enter details here

56.

On freeing a dynamic memory, if the pointer value is not modified, then the pointer points to?

Answer: C

None

Enter details here

Answer: A

No answer description available for this question.

Enter details here

58.

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. A.

Answer: B

 

malloc() and calloc() return void pointer for using a particular data type we made explicite type casting.

Enter details here

Answer: D

None

Enter details here

60.

Which header file should be included to use functions like malloc() and calloc()?

Answer: B

No answer description available for this question

Enter details here

Loading…
Tags: Memory Allocation Questions and Answers || Memory Allocation MCQ Questions and Answers || Memory Allocation GK Questions and Answers || Memory Allocation GK MCQ Questions || Memory Allocation Multiple Choice Questions and Answers || Memory Allocation GK || GK on Memory Allocation || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming