I find enum to be similar to an array,with the elements in it being numbered from 0. So what is the difference between an array and enum?
-
Hmm... where did you find this similarity? Enums are predefined sets of values (technically implemented as numbers 0...n) while arrays are some sort of collection. – Crozin Aug 04 '15 at 06:12
-
The difference between initializing an `enum` type and an array defining the same information? – The Brofessor Aug 04 '15 at 06:12
-
Possible Duplicate of http://stackoverflow.com/questions/13866683/enumeration-versus-array – Haris Aug 04 '15 at 06:13
-
Read about [arrays here](http://en.cppreference.com/w/c/language/array), about [enums here](http://en.cppreference.com/w/c/language/enum). Once you thoroughly read both the differences will probably be self-explanatory. – WhozCraig Aug 04 '15 at 06:20
-
@haris not duplicate. Different programming language. That is C++, this is C. It is a coincidence that the answers are the same. (well technically a matter of intentional design, but a coincience for our purposes). I believe there is a [meta post](http://meta.stackoverflow.com/questions/292329/) about us not closing questions as dupes just because the answers are the same. (particularly across different language tags) – Frames Catherine White Aug 04 '15 at 06:25
-
@Oxinabox, Ya i know the languages are the same. But i tagged it because the reason and the answer will be the same. I didn't know about the meta post. I get it now. :) – Haris Aug 04 '15 at 06:30
-
Definitely worth tagging. I would have linked that and said (rather than possible duplicate) "Related". I've mistakenly said possible duplicate before though, when I was thinking related. – Frames Catherine White Aug 04 '15 at 06:33
-
You can have an array of enums while not an enum of arrays, which says something. Arrays are collections of objects while enums are single objects of the underlying type with some values qualified with a special name. You should really consider reading a good book or tutorial on C. – legends2k Aug 04 '15 at 07:22
5 Answers
An Enum is basically a group of named constants. It is an alternative to numbered flag parameters. (It also doesn't have to be numbered from zero, you can specify the numbering.)
An Enum could be days of the week for example. A Enum could departments in a company: eg SALES, BILLING, HR ...
A array is a sequence of memory locations. It is a collection. Each element in that collection is indexed by a number. So using that number you can retrieve the value stored at that location. Much like the page number in a book lets you look up the content of that page, the index on an array lets you look up the value stored at that location.
For example, if your company had numbered physical mail boxes for each department (starting from zero): and you were creating some very simple software to let users log in to check how many letters they had uncollected, you might choose to store them in an Array of Ints. Where the index is the mail box number, and the value is the number of letters in the box.
Then for ease of programming, you might choose define the departments as Enums (as described before) such that you could index of department name. But that would be getting more advanced.
You may be confusing Enum, with Enumerable which is a term used in some languages to describe any collection type which can be iterated though in sequence (Eg IEnumerable in C#). This term is not often used in C. It is not in anyway the same at all as Enum.

- 27,368
- 21
- 87
- 137
-
Why the -1? its been a while since I did C, but I don' t think this is wrong? (Please correct me if it is, or provide suggestions for clarifying, I'ld love to be reminded.) – Frames Catherine White Aug 04 '15 at 06:20
-
I didn't give you -1, but I can see some problems in your answer. 1)`have to be numbered from zero` -> not correct. You can start from what you want/need. 2) `indexed lists` -> it is not good: list are something different in c. 3) Last consideration about c# is OT – LPs Aug 04 '15 at 06:43
-
@LPs: 1. my post explicitly states that it *doesn't* have to be numbered from zero. 2. I agree indexed list maybe misleading since that is specific term. (though not really in C, as I recall, You could implement something (normally a linked list, rather than an indexed one) and call it that, but its not part of any of the C standard libraries, to my knowledge). 3. I added that after the down-vote, but I guess a offtopic suggestion might bug some people. --- Thanks for taking some time to suggest. – Frames Catherine White Aug 04 '15 at 07:34
Array is a variable that can contain multiple elements with index starting from 0 whereas enum is an user defined datatype that contains a list of members for which an integer constant is assigned starting from 0. in case of enum the numbers starting from 0 are not indexes whereas in case of an array they are indexes. Also in case of enum you can assign your own constant values to the members that may or may not start from 0 and may or may not be in a sequence.

- 405
- 4
- 10
The main difference is that an array is a value and an enum is a type. And One main difference we can say that an array is a collection of other values (that is it contains other values, you can iterate through them or access individual ones by index), whereas an enum value is simply one atomic value. It doesn't contain any other values.

- 31
- 3
Both of them are totally different. Array is a value and enum is a type. array is a collection of different values whereas enum value is simply one value. Array is used to iterate among various values using index whereas enum is assigned some atomic value and iterated so that we can easily iterate the type.

- 933
- 7
- 18
Array's value are assigned by using = operator 'eg. int a[4]={1,2,3,4}' and enum is the user defined data type and it is assigned like enum days{sun,mon,tue,wed,thr,fri,sat}