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 643583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:17:55+00:00 2026-05-13T21:17:55+00:00

This question was asked to me in an interview. Suppose char *p=malloc(n) assigns more

  • 0

This question was asked to me in an interview.

Suppose char *p=malloc(n) assigns more than n,say N bytes of memory are allocated and free(p) is used to free the memory allocated to p.

can heap manager perform such faulty allocation ?
what happens now, will n bytes are freed or N bytes are freed?

is there any method to find how much memory is freed?

EDIT

is there any method to find how much memory is freed?

better than nothing,

mallinfo() can shed some light as pointed by “Fred Larson”

  • 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-05-13T21:17:56+00:00Added an answer on May 13, 2026 at 9:17 pm

    Yes, that’s what happens almost every time do you a malloc(). The malloc block header contains information about the the size of the block, and when free() is called, it returns that amount back to the heap. It’s not faulty, it’s expected operation.

    A simple implementation might, for instance, store just the size of the block in the space immediately preceding the returned pointer. Then, free() would look something like this:

    void free(void *ptr)
    {
        size_t *size = (size_t *)ptr - 1;
    
        return_to_heap(ptr, *size);
    }
    

    Where return_to_heap() is used here to mean a function that does the actual work of returning the specified block of memory to the heap for future use.

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

Sidebar

Related Questions

This question was asked at interview. Say I have a contract. [ServiceContract] public interface
This question was asked at interview.I need to have running total ( only using
This was the question asked in interview. Can we call one constructor from another
This question was asked to me in MS interview. I wanna know the exact
This question was asked to me in an interview: In C++, what if we
This was the question asked in an interview. NullPointerException is very common; why is
I was reading about this person's interview at a well-known search company. http://asserttrue.blogspot.com/2009/05/one-of-toughest-job-interview-questions.html He
This seems like a silly question but I would really like your comments and
I like to know can we define an interface within an interface. like interface

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.