SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Arpana Shree.AArpana Shree.A
By
1Enumerated Data Types
What is Enumerated DataWhat is Enumerated Data
Type???Type???
Enumerated Data type gives you an
opportunity to
Invent your own data type
Define what values of the variables of this data
type can take
The main purpose of he Enumerated data types is
to allow numbers to be replaced by words
2Enumerated Data Types
Enumerated typeEnumerated type is a data type whose list ofis a data type whose list of
values is specified by the programmer.values is specified by the programmer.
enum
enum_name
{identifier_list}
enum_type;
enum
BOOLEAN
{TRUE,FALSE
}
b1,b2;
SYNTAX EXAMPLE
3Enumerated Data Types
Another Way of having Syntax
enum
enum_name
{identifier_list}
enum_type;
SYNTAX
enum
BOOLEAN
{TRUE=0,
FALSE=1}
b1,b2;
EXAMPLE
4Enumerated Data Types
Note:
If no integer values are specified then the left
most word has integer value 0 and each one
after that is incremented by one from that
point. (0, 1, 2, 3, etc…) This also means that
the left-most word is generally the smallest
and the right-most word is generally the
largest.
5Enumerated Data Types
enum
BOOLEAN
{TRUE,FALSE
}
b1,b2;
EXAMPLE
In the example the User defined data
type BOOLEAN has been defined
The new data type has two values.
TRUE and FALSE
The word TRUE has an Integer value 0
The word FALSE has an Integer value
1
6Enumerated Data Types
Another Example:
enum Weekdays
{ Monday = 1,
Tuesday,
Wednesday,
Thursday,
Friday
};
EXAMPLE
enum Weekdays
{ Monday = 1,
Tuesday,
Wednesday=6,
Thursday,
Friday
};
EXAMPLE
7Enumerated Data Types
Guess the output:
Void main()
{
enum WeekDays{Mon,tue,wed
thurs,fri,sat,sun}days;
int i;
for(i=Mon;i<=fri;i++)
{
printf(“n %d”,i);
}
getch();
}
0
1
2
3
4
Output
8Enumerated Data Types
Now what happens!!!!
Void main()
{
enum
WeekDays{Mon=32767,tue,wed
thurs,fri,sat,sun}days;
int i;
for(i=Mon;i<=sun;i++)
{
printf(“n %d”,i);
}
getch();
}
What will be
the
OUTPUT????
Complier
throws an
error
Error: NUMERIC
CONSTANTS TOO LARGE
9Enumerated Data Types
Guess What Happens!!!!
Void main()
{
enum
WeekDays{Mon=32762,tue,wed
thurs,fri,sat,sun}days;
int i;
for(i=Mon;i<=sun;i++)
{
printf(“n %d”,i);
}
getch();
}
What will be
the
OUTPUT????
Does Complier
throw an
error?
Error: NUMERIC
CONSTANTS TOO LARGE
10Enumerated Data Types
Void main()
{
enum
WeekDays{Mon=32760,tue,wed
thurs,fri,sat,sun}days;
int i;
for(i=Mon;i<=sun;i++)
{
printf(“n %d”,i);
}
getch();
}
What will be
the
OUTPUT????
3276032760
3276132761
3257232572
3276332763
3276432764
3276532765
3276632766
11Enumerated Data Types
Void main()
{
enum WeekDays{Mon=-1,tue,wed
thurs,fri,sat,sun}days;
int i;
for(i=Mon;i<=sun;i++)
{
printf(“n %d”,i);
}
getch();
}
What will be
the
OUTPUT????
-1-1
00
11
22
33
44
55
12Enumerated Data Types
Type-definition
The type definition statement is used to allow user defined
data types to be defined
using other already available data types.
Typedef
existing_data_type
new_user_define_
data_type;
SYNTAX
Typedef
int
Integer
EXAMPLE
13Enumerated Data Types
The example above
simply creates an alternative data
type name
• Integer for the built in data type
called “int”.
Typedef
int
Integer
EXAMPLE
14Enumerated Data Types
How Type def is used in
structure
typedef struct
{
char names[10];
int age;
int marks;
} WEIGHT;
WEIGHT a1,a2,a3;
struct stud
{
char names[10];
int age;
int marks;
};
Typedef struct stud STD
STD s1,s2,s3 15Enumerated Data Types
• In the above example STD is a new name
for structure, Now every time it is not
required to use Struct Stud for creating
structure variable
16Enumerated Data Types
Bit Fields
While declaring a integer data type members within a structure,
its size will be 16 bits. There are occasions where data requires
much less than 16 bits space. We can overcome the wastage of
the space by specifying the bit length
The Bit length specifies the number of bits that should be
allotted to a member
17Enumerated Data Types
-Continued Bit field
Member of a structure whose size (in bits) has been specified
Enable better memory utilization
Must be declared as int or unsigned
Cannot access individual bits
Same address to the memory
18Enumerated Data Types
Declaration Syntax
struct <tagname>
{
datatype name1:bit-length;
datatype name2:bit-length;
.
.
};
Follow unsigned or
int member with a
colon (:) and an
integer constant
representing the width
of the field
NOTE
19Enumerated Data Types
Example
struct employee
{
unsigned int age: 7;
unsigned int sex: 1;
unsigned int marital_stat: 1;
unsigned int children: 4;
}emp;
20Enumerated Data Types
Bit Field Bit length Range
Age 7 27
- 1
(0 to 127)
Sex 1 0 or 1
Marital_stat 1 0 or 1
children 4 24
– 1
(0 to 15)
21Enumerated Data Types
22Enumerated Data Types

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Arrays
ArraysArrays
Arrays
 
C pointer
C pointerC pointer
C pointer
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Data types
Data typesData types
Data types
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Structure in C
Structure in CStructure in C
Structure in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
File in C language
File in C languageFile in C language
File in C language
 
C string
C stringC string
C string
 
structure and union
structure and unionstructure and union
structure and union
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 

Andere mochten auch (17)

Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
Ceh v5 module 04 enumeration
Ceh v5 module 04 enumerationCeh v5 module 04 enumeration
Ceh v5 module 04 enumeration
 
Operatingsystems lecture2
Operatingsystems lecture2Operatingsystems lecture2
Operatingsystems lecture2
 
Preprocessors
Preprocessors Preprocessors
Preprocessors
 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by Faixan
 
VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)VHDL - Enumerated Types (Part 3)
VHDL - Enumerated Types (Part 3)
 
Preprocessor in C
Preprocessor in CPreprocessor in C
Preprocessor in C
 
Data types in C
Data types in CData types in C
Data types in C
 
File operations in c
File operations in cFile operations in c
File operations in c
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
 
File handling in c
File handling in c File handling in c
File handling in c
 
File handling in c
File handling in cFile handling in c
File handling in c
 
C if else
C if elseC if else
C if else
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
Type Casting in C++
Type Casting in C++Type Casting in C++
Type Casting in C++
 

Ähnlich wie Enumerated data types in C

Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsatifmugheesv
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.pptAqeelAbbas94
 
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxAmrutaNavale2
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++ Hridoy Bepari
 
13.1 User-defined data types.pptx
13.1 User-defined data types.pptx13.1 User-defined data types.pptx
13.1 User-defined data types.pptxSooraj Rajmohan
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfYRABHI
 
Data Types | CS8251- Programming in c | Learn Hub
Data Types | CS8251- Programming in c | Learn HubData Types | CS8251- Programming in c | Learn Hub
Data Types | CS8251- Programming in c | Learn HubLearn Hub
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structsSaad Sheikh
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGEPRASANYA K
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introductionnikshaikh786
 

Ähnlich wie Enumerated data types in C (20)

Data types in C
Data types in CData types in C
Data types in C
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 
Data Handling
Data HandlingData Handling
Data Handling
 
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
 
Data type
Data typeData type
Data type
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
13.1 User-defined data types.pptx
13.1 User-defined data types.pptx13.1 User-defined data types.pptx
13.1 User-defined data types.pptx
 
Data types
Data typesData types
Data types
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
Data Types | CS8251- Programming in c | Learn Hub
Data Types | CS8251- Programming in c | Learn HubData Types | CS8251- Programming in c | Learn Hub
Data Types | CS8251- Programming in c | Learn Hub
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 
C PROGRAMMING LANGUAGE
C  PROGRAMMING  LANGUAGEC  PROGRAMMING  LANGUAGE
C PROGRAMMING LANGUAGE
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Data types
Data typesData types
Data types
 
Data types
Data typesData types
Data types
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 

Mehr von Arpana shree

Banking locker security using Image processing
Banking locker security using Image processingBanking locker security using Image processing
Banking locker security using Image processingArpana shree
 
Graphical Password authentication using Hmac
Graphical Password authentication using HmacGraphical Password authentication using Hmac
Graphical Password authentication using HmacArpana shree
 
Intellectual property rights
Intellectual property rightsIntellectual property rights
Intellectual property rightsArpana shree
 
Two factor autentication in Gmail
Two factor autentication in GmailTwo factor autentication in Gmail
Two factor autentication in GmailArpana shree
 
System Z operating system
System Z operating systemSystem Z operating system
System Z operating systemArpana shree
 

Mehr von Arpana shree (9)

Evo mouse
Evo mouseEvo mouse
Evo mouse
 
Cryptography
CryptographyCryptography
Cryptography
 
Banking locker security using Image processing
Banking locker security using Image processingBanking locker security using Image processing
Banking locker security using Image processing
 
Graphical Password authentication using Hmac
Graphical Password authentication using HmacGraphical Password authentication using Hmac
Graphical Password authentication using Hmac
 
Intellectual property rights
Intellectual property rightsIntellectual property rights
Intellectual property rights
 
Two factor autentication in Gmail
Two factor autentication in GmailTwo factor autentication in Gmail
Two factor autentication in Gmail
 
Database security
Database securityDatabase security
Database security
 
System Z operating system
System Z operating systemSystem Z operating system
System Z operating system
 
RSA algorithm
RSA algorithmRSA algorithm
RSA algorithm
 

Kürzlich hochgeladen

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Kürzlich hochgeladen (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

Enumerated data types in C

  • 2. What is Enumerated DataWhat is Enumerated Data Type???Type??? Enumerated Data type gives you an opportunity to Invent your own data type Define what values of the variables of this data type can take The main purpose of he Enumerated data types is to allow numbers to be replaced by words 2Enumerated Data Types
  • 3. Enumerated typeEnumerated type is a data type whose list ofis a data type whose list of values is specified by the programmer.values is specified by the programmer. enum enum_name {identifier_list} enum_type; enum BOOLEAN {TRUE,FALSE } b1,b2; SYNTAX EXAMPLE 3Enumerated Data Types
  • 4. Another Way of having Syntax enum enum_name {identifier_list} enum_type; SYNTAX enum BOOLEAN {TRUE=0, FALSE=1} b1,b2; EXAMPLE 4Enumerated Data Types
  • 5. Note: If no integer values are specified then the left most word has integer value 0 and each one after that is incremented by one from that point. (0, 1, 2, 3, etc…) This also means that the left-most word is generally the smallest and the right-most word is generally the largest. 5Enumerated Data Types
  • 6. enum BOOLEAN {TRUE,FALSE } b1,b2; EXAMPLE In the example the User defined data type BOOLEAN has been defined The new data type has two values. TRUE and FALSE The word TRUE has an Integer value 0 The word FALSE has an Integer value 1 6Enumerated Data Types
  • 7. Another Example: enum Weekdays { Monday = 1, Tuesday, Wednesday, Thursday, Friday }; EXAMPLE enum Weekdays { Monday = 1, Tuesday, Wednesday=6, Thursday, Friday }; EXAMPLE 7Enumerated Data Types
  • 8. Guess the output: Void main() { enum WeekDays{Mon,tue,wed thurs,fri,sat,sun}days; int i; for(i=Mon;i<=fri;i++) { printf(“n %d”,i); } getch(); } 0 1 2 3 4 Output 8Enumerated Data Types
  • 9. Now what happens!!!! Void main() { enum WeekDays{Mon=32767,tue,wed thurs,fri,sat,sun}days; int i; for(i=Mon;i<=sun;i++) { printf(“n %d”,i); } getch(); } What will be the OUTPUT???? Complier throws an error Error: NUMERIC CONSTANTS TOO LARGE 9Enumerated Data Types
  • 10. Guess What Happens!!!! Void main() { enum WeekDays{Mon=32762,tue,wed thurs,fri,sat,sun}days; int i; for(i=Mon;i<=sun;i++) { printf(“n %d”,i); } getch(); } What will be the OUTPUT???? Does Complier throw an error? Error: NUMERIC CONSTANTS TOO LARGE 10Enumerated Data Types
  • 11. Void main() { enum WeekDays{Mon=32760,tue,wed thurs,fri,sat,sun}days; int i; for(i=Mon;i<=sun;i++) { printf(“n %d”,i); } getch(); } What will be the OUTPUT???? 3276032760 3276132761 3257232572 3276332763 3276432764 3276532765 3276632766 11Enumerated Data Types
  • 12. Void main() { enum WeekDays{Mon=-1,tue,wed thurs,fri,sat,sun}days; int i; for(i=Mon;i<=sun;i++) { printf(“n %d”,i); } getch(); } What will be the OUTPUT???? -1-1 00 11 22 33 44 55 12Enumerated Data Types
  • 13. Type-definition The type definition statement is used to allow user defined data types to be defined using other already available data types. Typedef existing_data_type new_user_define_ data_type; SYNTAX Typedef int Integer EXAMPLE 13Enumerated Data Types
  • 14. The example above simply creates an alternative data type name • Integer for the built in data type called “int”. Typedef int Integer EXAMPLE 14Enumerated Data Types
  • 15. How Type def is used in structure typedef struct { char names[10]; int age; int marks; } WEIGHT; WEIGHT a1,a2,a3; struct stud { char names[10]; int age; int marks; }; Typedef struct stud STD STD s1,s2,s3 15Enumerated Data Types
  • 16. • In the above example STD is a new name for structure, Now every time it is not required to use Struct Stud for creating structure variable 16Enumerated Data Types
  • 17. Bit Fields While declaring a integer data type members within a structure, its size will be 16 bits. There are occasions where data requires much less than 16 bits space. We can overcome the wastage of the space by specifying the bit length The Bit length specifies the number of bits that should be allotted to a member 17Enumerated Data Types
  • 18. -Continued Bit field Member of a structure whose size (in bits) has been specified Enable better memory utilization Must be declared as int or unsigned Cannot access individual bits Same address to the memory 18Enumerated Data Types
  • 19. Declaration Syntax struct <tagname> { datatype name1:bit-length; datatype name2:bit-length; . . }; Follow unsigned or int member with a colon (:) and an integer constant representing the width of the field NOTE 19Enumerated Data Types
  • 20. Example struct employee { unsigned int age: 7; unsigned int sex: 1; unsigned int marital_stat: 1; unsigned int children: 4; }emp; 20Enumerated Data Types
  • 21. Bit Field Bit length Range Age 7 27 - 1 (0 to 127) Sex 1 0 or 1 Marital_stat 1 0 or 1 children 4 24 – 1 (0 to 15) 21Enumerated Data Types