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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:26:13+00:00 2026-05-23T05:26:13+00:00

i just experiment the things on the c language could you answer my question

  • 0

i just experiment the things on the c language
could you answer my question regarding the program i’ve written

void main()
{
    char *p,; // created a  pointer pointing to string
    p = (char *) malloc(50); // dynamically create 50 bytes.
    strcpy(p, "this code is written about the dynamic allocation");
    p += 20;
    free(p);
}

Now could anyone tell me what is the effect of free(p) statement will the last 30 bytes will be freed of and used for the future memory allocation.? what would be the output?

  • 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-23T05:26:14+00:00Added an answer on May 23, 2026 at 5:26 am

    You are not supposed to free any addresses but those returned by malloc(), calloc() or realloc(). And p + 20 is no such address.
    http://codepad.org/FMr3dvnq shows you that such a free() is likely to fail.

    The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc() or realloc(). Otherwise, or if free(ptr) has already been called before, undefined behavior occurs. If ptr is NULL, no operation is performed.

    Does the pointer passed to free() have to point to beginning of the memory block, or can it point to the interior? is also worth reading.

    Even if you could use free() on any pointer that points to a malloc’d memory – your could would free it twice since you are calling free() on more than one memory inside that area. And double-frees are evil as they can result in security holes.

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

Sidebar

Related Questions

One of the main things I wanted to achieve in my experimental programming language
Just to experiment assembly in C++, I tried the following, which is causing the
This sounds funny..just a little experiment. i wanted to simulate a drag drop of
just a quick question: I am a CS undergrad and have only had experience
Just how much slower are events? I have written a streaming XML parser (that
I have just started exploring TWILL . Twill is an amazing scripting language for
Just as a personal experiment, in order to try to learn better about programming
Moderator note: This question is not a good fit for our question and answer
I'm doing a short project just to experiment writing without the use of nib
I'm just now beginning to experiment with IoC containers. Currently, I'm using a home-grown

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.