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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:41:33+00:00 2026-05-22T14:41:33+00:00

My question is very simple one. Say we have: char* ptr = (char*) malloc(sizeof(char)*SIZE);

  • 0

My question is very simple one. Say we have:

char* ptr = (char*) malloc(sizeof(char)*SIZE);
ptr+= SIZE/2;
free(ptr);

What happens when we free the pointer? Is it undefined operation?
Does it free all of SIZE buffer or only the remaining SIZE/2?
Thanks in advance for disambiguating this for me.

  • 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-22T14:41:34+00:00Added an answer on May 22, 2026 at 2:41 pm

    Your program will probably crash: the free() operation is actually quite simple in C, but works only on the original allocated address.

    The typical memory allocator works like this pseudo code:

    • ask to alloc 64 bytes
    • allocator allocs 70 bytes (6 bytes more)
    • the first 2 bytes is set to a “signature”, a pattern recognized by the allocator to identify the memory allocated by him
    • the next 4 bytes denote the allocated size
    • return a pointer to the start of the 7th byte

    So when you call free(ptr), the allocator goes 6 bytes before your pointer to check for the signature. If it doesn’t find the signature, it crashes 🙂

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

Sidebar

Related Questions

Here is one very simple question(or at least at first sight).Let's say we have
Here's a very simple question. I have an SP that inserts a row into
I have a very simple question. I want to test whether a particular port
I have a java threads related question. To take a very simple example, lets
My question is very simple: Is there any solution to install xCode, or equivalent,
Very simple question, is there any cloud server enviroments avaliable these days for us
Very simple question, I made the following program : #include <stdlib.h> int main(int argc,
Very simple question. What does the term 'seeding' mean in general? I'll put the
Maybe a very simple question. How can I put in this code <Query> <Where>
This is a very simple question with a simple answer, but it is not

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.