- 1

C PROBLEM

How to you ENUM in C and what is the Syntax of it ?

21st Mar 2019, 5:13 PM
Dynno
Dynno - avatar
1 Resposta
+ 1
enum stands for "enumeration" and it is a user-defined data type in C. An enum can be declared as; enum enum_var_name {list_of_constants separated by commas}; EX: enum week {Mon, Tue, Wed, Thu, Fri, Sat, Sun}; By default, these constants' index numbers start from 0. i.e: Mon has the index number 0, Tue has the number 1, etc. If you need to customize the index numbers, it is possible as follows. Ex: Let's say you wanna start the indexing of weekdays from 5, not from 0, and weekends from 12. enum week {Mon = 5, Tue, Wed, Thu, Fri, Sat = 12, Sun}; In here, the index values are assigned as follows. Mon -> 5 Tue -> 6 Wed -> 7 Thu -> 8 Fri -> 9 Sat -> 12 Sun -> 13 I hope you have got an idea.
7th Jul 2019, 5:36 PM
Shashika Bandara