Results 1 to 4 of 4

Thread: Dynamic allocation of an array structure

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    Dynamic allocation of an array structure

    I have some difficulties to allocate a table structure dynamically. The thing that stuck is that I absolutely want this table structure is declared as a global variable.

    This is my structure:
    Code:
    typedef struct
     (
         char * name;
         char * firstname;
     Person);
    I can do without using a global variable but not with global variable.

    Thank you in advance for your help.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Dynamic allocation of an array structure

    Code:
    / * Main.c * /
    
     # include "pers.h"
     # include <stdlib.h>
    
     int main (void)
     (
       people = malloc (sizeof * people);
    
       persons [0]. name = "dn";
       persons [0]. first_name = "mac";
    
       free (people);
    
       return 0;
     )

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Dynamic allocation of an array structure

    The address of a variable returned by the reference operator (&) is not an l-value, Dynamic allocation of arrays of more than one dimension is not so easily done, because dynamic allocation of an n-dimensional array actually requires dynamic allocation of n 1-dimensional arrays.Dynamic allocation is the automatic allocation of memory. Unlike declarations, which load data onto the programs data segment.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Dynamic allocation of an array structure

    Nothing special, as it is a global one another:


    Code:
     typedef struct
     (
         char * name;
         char * firstname;
     Person);
    
     extern person * people;

Similar Threads

  1. How to add new RAID array to dynamic pool
    By Ella Mentry in forum Hardware Peripherals
    Replies: 2
    Last Post: 10-02-2012, 10:52 AM
  2. Dynamic memory allocation for two-dimensional arrays
    By Ucchal in forum Technology & Internet
    Replies: 1
    Last Post: 23-09-2010, 06:23 PM
  3. Memory allocation in C++
    By Prashobh Mallu in forum Software Development
    Replies: 5
    Last Post: 08-02-2010, 09:56 AM
  4. Assigning an array to an array
    By MACE in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 05:19 PM
  5. Drive letter allocation
    By phaneesh in forum Windows XP Support
    Replies: 2
    Last Post: 22-01-2007, 11:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,719,710.74900 seconds with 17 queries