Results 1 to 4 of 4

Thread: Distinguish between realloc() and free() of C++

  1. #1
    Join Date
    Dec 2009
    Posts
    31

    Distinguish between realloc() and free() of C++

    Hi, Everyone. I am studying in the first year of MscCS. I don't know much about the C++ programming language. I just started to learn the C++ language. But I have to submit the assignment on the realloc() and free() functions of the C++. I don't know what are those functions. So, I want to know about the realloc() and free() functions of C++. I also want to know for what purpose those functions are used and how they can be used in the program. Can anyone help me about the those functions?

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    realloc() and free() of C++

    Hello, If pointer parameter is not a valid pointer then Undefined results occur. No action can occur if there the value is null of the pointer parameter. The realloc() function changes the size of the block of memory that is pointed to by the pointer parameter to the number of bytes specified by the Size parameter. Then a new pointer is return to the block by the realloc() function. The pointer that is specified by the Pointer parameter can be created with the malloc, realloc, or calloc subroutines. They can not be deallocated with the free or realloc subroutines.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Distinguish between realloc() and free()

    Hi, The free() function deallocates a block of memory that has been previously allocated by the malloc() function. If pointer parameter is not a valid pointer then the undefined results can occur. No action can occur if the value of the pointer parameter is a null value. I think it is better enough for you to understand about free() function and what it is actually does. If you till doesn't understand then give me reply. Have Nice Day!

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Distinguish between realloc() and free()

    I suggest you to noticed the one aspect that if you use the new keyword to allocate memory then you can not use realloc() function. It can lead to crash in the application. free() function is a macro used to destroy the memory that is previously been allocated. If there is no memory for allocation then we use the realloc() function to reallocate memory according to given size. It will free previous allocated memory & allocate new one memory block using malloc() function. For example : int *q = realloc(q,sizeof(q)*2)

Similar Threads

  1. Replies: 10
    Last Post: 01-11-2011, 10:23 AM
  2. How to distinguish real and fake acekard 2i?
    By alice841007 in forum Portable Devices
    Replies: 1
    Last Post: 17-01-2011, 03:03 PM
  3. Cannot distinguish between pci and pcie slots ?
    By Udyami in forum Motherboard Processor & RAM
    Replies: 3
    Last Post: 28-11-2010, 04:38 AM
  4. Replies: 1
    Last Post: 23-12-2005, 03:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,019,573.43148 seconds with 17 queries