Enum(s) and Memory

This is a discussion on Enum(s) and Memory within the C++ Programming forums, part of the General Programming Boards category; How does an enumerated data type use memory? let's say i have enum Family { brother, sister, mom, dad }; ...

  1. #1
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256

    Question Enum(s) and Memory

    How does an enumerated data type use memory?
    let's say i have

    enum Family { brother, sister, mom, dad };

    then i define it

    Family intermediate;

    How much space is set aside for intermediate?

    And what's the difference/advantage of an enumerated data type and a whole bunch of ints?
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >How much space is set aside for intermediate?
    Code:
    cout<< sizeof intermediate <<endl;
    >And what's the difference/advantage of an enumerated data type and a whole bunch of ints?
    An enumeration is more restrictive and provides more protection as a result. It also acts as documentation better than a "whole bunch of ints".
    My best code is written with the delete key.

  3. #3
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    it says 4.. does this mean 4 bytes. type long?
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >does this mean 4 bytes.
    Yes.

    >type long?
    Does it matter?
    My best code is written with the delete key.

  5. #5
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256
    Jeeze!! prelude!
    thanks for answering me though
    Clear the mines from our Shazbot!
    Get the enemy Shazbot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A snake game - Memory problem
    By gavra in forum C Programming
    Replies: 29
    Last Post: 11-23-2008, 11:58 AM
  2. VOID (my understanding is void)
    By LLINE in forum C++ Programming
    Replies: 5
    Last Post: 11-07-2008, 03:10 PM

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