malloc () function important role - Data Structure

Q.  Which function plays an important role in returning the address of memory block allocated to locate / store  a node especially while declaring ' top ' in the linked representation of the Stack?
- Published on 28 Aug 15

a. galloc ()
b. falloc ()
c. malloc ()
d. calloc ()

ANSWER: malloc ()
 

    Discussion

  • Nirja Shah   -Posted on 16 Nov 15
    malloc function allocates memory dynamically. When you implement stack as a linklist, then you can allocate memory at run time as follows. Consider struct node is already created.
    struct node ∗newNode;
    newNode=(struct node∗)malloc(sizeof(struct node));

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)