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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:58:48+00:00 2026-06-08T12:58:48+00:00

I have structure containing an array. Something like given below: struct Node { int

  • 0

I have structure containing an array. Something like given below:

struct Node
{
    int a;
    char a1[25];
}obj;

main()
{
    struct Node *p = malloc(sizeof(struct Node));
    p->a=10;
}

I would like to know is two different memory section is allocated for this piece of code one from stack for storing structure node and other from heap for storing node pointed to by pointer p?

  • 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-08T12:58:51+00:00Added an answer on June 8, 2026 at 12:58 pm

    After Edit:

    struct Node
    {
        int a;
        char a1[25];
    }obj;
    

    Instead it will be allocated in data section I guess. This code is modified little-bit like

    #include <stdio.h>
    #include <stdlib.h>
    
    struct Node
    {
        int a;
        char a1[25];
    }obj;
    
    int global_data;
    
    int main()
    {
       // struct Node *p = malloc(sizeof(struct Node));
       // p->a=10;
    
        obj.a = 10;
    
        return 0;
    }
    

    And when we look at assembly code.

     .file   "ada.c"
            .comm   obj,32,32
            .comm   global_data,4,4
            .text
            .globl  main
            .type   main, @function
    main:
    .LFB0:
            .cfi_startproc
            pushq   %rbp
            .cfi_def_cfa_offset 16
            .cfi_offset 6, -16
            movq    %rsp, %rbp
    

    both global_data and obj allocated in same location. i.e uninitialized data section. There will be no chance to allocate in heap. Because there is no call to malloc().

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

Sidebar

Related Questions

I have a table containing 60 million rows. The structure is like entryid, date,
I have a structure like this struct structure { BaseObject &A; //BaseObject has a
I have a structure array containing fields as structure arrays of varying length. For
I have a REST web service that returns a structure containing an array of
Suppose I have a structure in C++ containing a name and a number, e.g.
I have a deep tree structure built with lists, containing lists and floats. I
I have structure like this. <ul class=gallerylist> <li> <image ...> <input ...> </li> <li>
I have a tree-like object structure that consists of two types of objects: object
I have this array structure: Array ( [0] => Array ( [0] => Array
I have a dictionary of struct, where one member is a list containing varying

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.