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

  • SEARCH
  • Home
  • 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 6145175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:45:28+00:00 2026-05-23T18:45:28+00:00

In the following program, the address allocated by the realloc falls in the address

  • 0

In the following program, the address allocated by the realloc falls in the address range allocated by malloc. I am not able to understand why. (Please overlook freeing of memory.)

#include<stdio.h>
#include<stdlib.h>


   struct MyClass 
   {
      double num;
   };

   struct node
   {
      MyClass* array;
      int max_size;
      double w[10]; //used only to increase the size of node
      long double ld;
   };




  void fill(struct node *ptr)
  {
      MyClass *tmp;

      if(ptr->array==NULL )
         tmp = (MyClass*)realloc(ptr->array, 10*sizeof(MyClass) );

         printf("addr range of node: %p  <-->  %p\n", ptr, &(ptr->ld));
         printf("addr recvd by tmp: %p\n", tmp);
      if(tmp)
      {
        ptr->array=tmp;
        ptr->array[0].num=32.23;
        ptr->ld = 33.1321;
      }
  }


 struct node*
   allocator()
      {
         struct node* ptr =(struct node*)malloc(sizeof(struct node*));
         ptr->max_size= 232;
         ptr->ld =321.3425;
         ptr->array = __null;
         return ptr;
      }

  int
   main()
   {
      struct node *ptr =allocator();
      fill(ptr);
      printf(" %Lf  %lf\n", ptr->ld, ptr->array[0].num);  
      return 0;
   }

output:

addr range of node: 0xa2a010  <-->  0xa2a070

addr recvd by tmp: 0xa2a030

 33.132100  32.230000

Executed on x64 Linux.

  • 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-23T18:45:29+00:00Added an answer on May 23, 2026 at 6:45 pm

    struct node* ptr =(struct node*)malloc(sizeof(struct node*));

    should be struct node* ptr =(struct node*)malloc(sizeof(struct node));

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

Sidebar

Related Questions

Please look at the following program, the error is invalid effective address calculation and
In my program, I have a list of server address in the following format:
The following code binds specified ip address to socket in main program globally. import
Please, observe the following simple program (based on the example from the protobuf-net project
I have the following code in my Android program List<Address> addressList = geoCoder.getFromLocation(37.790551,-122.433931, 1);
I have the following program. However, I can't understand why I have to pass
The following program is very simple: it outputs a single dot each half a
Consider following program: static void Main (string[] args) { int i; uint ui; i
In following program . I have one doubt. I have declared one global variable
The following program is a basic linked list divided in 3 classes. In the

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.