A Way For Learning

Dynamic Memory Allocation - C Programming

No comments

  • allocating memory at runtime
  • defined in stdlib.h
  • malloc() allocates requested size of bytes and returns a void pointer pointing to the first byte of the allocated space
  • calloc() allocates space for an array of elements, initialize them to zero and then return a void pointer to the memory
  • free releases previously allocated memory
  • realloc modify the size of previously allocated space
  • Difference between malloc() and calloc()
    • calloc() initializes the allocated memory with 0 value. malloc() initializes the allocated memory with garbage values.
    • Number of arguments is 2 and Number of argument is 1
    • Syntax of calloc : (cast_type *)calloc(blocks , size_of_block);
    • Syntax of malloc:(cast_type *)malloc(Size_in_bytes);

No comments :

Post a Comment