adplus-dvertising
frame-decoration

Question

If malloc() successfully allocates memory it returns the number of bytes it has allocated.
# include<stdio.h>
#include<stdlib.h>
void fun(int *a)
{
    a = (int*)malloc(sizeof(int));
}
int main()
{
    int *p;
    fun(p);
    *p = 6;
    printf("%dn",*p);
    return(0);
}

a.

May not work

b.

Works and prints 6

c.

Compiler Error

d.

Runtime error

Posted under C Programming

Answer: (a).May not work

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

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

Similar Questions

Discover Related MCQs

Q. Which of the following is an example for non linear data type?

Q. The advantage of using linked lists over arrays is that ________

Q. The type of linked list in which the node does not contain any pointer or reference to the previous node:

Q. Choose the statement which is incorrect with respect to dynamic memory allocation.

Q. Local variables are stored in an area called ___________

Q. When we dynamically allocate memory is there any way to free memory during run time?

Q. Can we increase the size of statically allocated array?

Q. Can We increase the size of dynamically allocated array?

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

Q. malloc() returns a NULL if it fails to allocate the requested memory.

Q. Where does the uninitialized data gets stored in memory?

Q. malloc() allocates memory from the heap and not from the stack.

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

Q. Which languages necessarily need heap allocation in the run time environment?

Q. Which of the following is/are true?

Q. Among 4 header files, which should be included to use the memory allocation functions like malloc(), calloc(), realloc() and free()?

Q. Which function is used to delete the allocated memory space?

Q. What is the return type of malloc() or calloc()?

Q. Which of the following statement is correct prototype of the malloc() function in c ?

Q. Specify the 2 library functions to dynamically allocate memory?