Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9088401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:54:04+00:00 2026-06-16T21:54:04+00:00

Reading some literature, I was able to grasp that realloc takes in a void

  • 0

Reading some literature, I was able to grasp that realloc takes in a void pointer and a size variable and re-allocates the memory of the block the void pointer points to.

  • What will happen if realloc is called on an integer pointer (int *)
    with a size of character? And vice versa.

  • What can be a possible application of this? (An example would definitely help.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:54:05+00:00Added an answer on June 16, 2026 at 9:54 pm

    The realloc() function is the all-in-one memory management system.

    • If called with a null pointer and a non-zero size, it allocates memory.
    • If called with a valid pointer and a zero size, it frees memory.
    • If called with a valid pointer and a non-zero size, it changes the size of the allocated memory.

    If you call realloc() with an invalid pointer — one which was not obtained from malloc(), calloc() or realloc() — then you get undefined behaviour.

    You could pass realloc() an integer pointer to an allocated space of sizeof(char) bytes (1 byte), but you’d be in danger of invoking undefined behaviour. The problem is not with realloc(); it is with the code that was given an unusable integer pointer. Since only 1 byte was allocated but sizeof(int) is greater than 1 (on essentially all systems; there could be exceptions, but not for someone asking this question), there is no safe way to use that pointer except by passing it to free() or realloc().

    Given:

    int *pointer = malloc(sizeof(char));
    

    you cannot do *pointer = 0; because there isn’t enough space allocated (formally) for it to write to. You cannot do int x = *pointer; because there isn’t enough space allocated (formally) for it to read from. The word ‘formally’ is there because in practice, the memory allocators allocate a minimum size chunk, which is often 8 or 16 bytes, so there actually is space after the one byte. However, your are stepping outside the bounds of what the standard guarantees, and it is possible to conceive of memory allocators that would hand you exactly one byte. So, don’t risk it. An integer pointer to a single byte of allocated memory is unusable except as an argument to the memory allocation functions.

    The first argument to realloc() is a void *. Since you’re going to have a prototype in scope (#include <stdlib.h>), the compiler will convert the int * to a void * (if there’s anything to do for such a cast), and as long as the space pointed at was allocated, everything will be fine; realloc() will change the allocation size, possibly returning the same pointer or possibly returning a different pointer, or it will release the space if the new size is zero bytes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading some statistics about my app I saw that it takes over one
When reading some FreeBSD source code (See: radix.h lines 158-173), I found variable declarations
I am reading some book and I have encountered a piece of code that
I am reading some materials on Java serialization and found that, for self defined
While reading some programming books, I notice that the authors says that, in OOP,
Reading some articles, told me that soft keys varies between devices. Some says -6
After reading some stuff it seems I can map the SMBIOS memory and parse
After reading some tutorials I am still unclear on some points about memory management
I am reading some code that looks like that: Class_Menu.php: <?php class Menu {
Reading some book that said the servlet is singleton from the container side. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.