Like Tree1Likes
  • 1 Post By tabstop

Memory in C

This is a discussion on Memory in C within the C Programming forums, part of the General Programming Boards category; I have this code: Code: struct List{ int info; int member; } int main(){ struct List *tmp; tmp=calloc(sizeof(List)); } I ...

  1. #1
    hqt
    hqt is offline
    Registered User
    Join Date
    Aug 2011
    Posts
    115

    Question Memory in C

    I have this code:
    Code:
    struct List{
    int info;
    int member;
    }
    int main(){
    struct List *tmp;
    tmp=calloc(sizeof(List));
    }
    I want to ask is: when I'm call tmp=calloc(sizeof(List)), It will find two consecutive memory block and create info and member or It will find two different memory block to create them.

    thanks

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    It will "find" one block that is the size of a List object.
    guitargod likes this.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    If you are asking if they are stored together the answer is yes. As Tabstop points out it's one object (a struct(ure)) not two variables.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic memory and realloc(), freeing memory
    By C_Sparky in forum C Programming
    Replies: 6
    Last Post: 10-06-2010, 08:55 PM
  2. Replies: 12
    Last Post: 04-11-2010, 08:14 AM
  3. Allocate memory inside allocated memory block?
    By Heidi_Nayak in forum C Programming
    Replies: 14
    Last Post: 04-15-2009, 05:19 PM
  4. Finding memory address using memory pattern
    By MindWorX in forum C++ Programming
    Replies: 1
    Last Post: 05-25-2008, 08:20 AM
  5. Replies: 2
    Last Post: 09-28-2006, 02:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21