Design decisions on data structures

A

asm

Hi All,

I would like to know what should be the criteria to choose between a
union / structure. Also switch statement vs if - else. I know switch
only 'switches' on
integer types. Some example would be of help.

Thanks,
ASM
 
J

Jack Klein

Hi All,

I would like to know what should be the criteria to choose between a
union / structure. Also switch statement vs if - else. I know switch
only 'switches' on
integer types. Some example would be of help.

Thanks,
ASM

Unions and structures are very different things. A structure always
has the same type of contents and those contents can consist of many
different data types. A union can contain different data types, but
only one of them at a time.

If you don't know of any reasons why you should use unions, then you
most surely should use structures.

As for "if...else if...else" rather than switch statements, use
whichever one makes your code clearer. Generally, if there are more
than three possibilities and they are all based on the value of an
integer object, that means using switch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top