Thread: what is the size of following struct

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    7

    what is the size of following struct

    consider the following struct

    Code:
    struct something {
            int i;
            struct something *somepointer;
    } somevariable;
    what is the result of calling sizeof(somevariable) ? please explain

  2. #2
    Registered User
    Join Date
    Apr 2005
    Posts
    134
    8 bytes ?? (Assuming its a 32 bit computer and int means (long) )

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The result will be sizeof somevariable. As Dave pointed out it depends. Since not every compiler will use the same size for int and not every compiler will use the same size of a pointer to a struct.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>what is the result of calling sizeof(somevariable) ?
    Write your own program to answer that question, you shouldn't expect others to do that for you.

    >>explain
    Sounds like a homework question... Have fun working it out
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    7
    got it...

    thanks to all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  4. Replies: 11
    Last Post: 03-25-2003, 05:13 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM