Professional Documents
Culture Documents
Subject: C' Programming For Problem Solving Subject Code: 18CPS23
Subject: C' Programming For Problem Solving Subject Code: 18CPS23
a list
‘1’ in a sequential.
enum (enumeration) Data Type (CONTD….)
Syntax:
enum identifier{value1,value2,….,valuen};
Where,
enum is a keyword.
identifier is a user-defined enumerated data type
which can be used to declare variables that can be have
one of the values enclosed within the braces (known as
enumeration constants).
value1,value2,….,valuen represents enumerated
variables.
enum (enumeration) Data Type (CONTD….)
Example 1:
enum month{jan,feb,mar,apr,may,jun,jul,aug,
sep,oct,nov,dec};
Here,
jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov
and dec variables assignd to 0,1,2,3,4,5,6,
7,8,9,10 and 11
Means
jan=0,feb=1,mar=2,apr=3,may=4,jun=5,jul=6,
aug=7,sep=8,oct=9,nov=10 and dec=11.
enum (enumeration) Data Type (CONTD….)
Example 2:
enum day{Mon,Tue,Wed,Thu,Fri,Sat,Sun};
Means
Sun=6.
enum (enumeration) Data Type (CONTD….)
Example 3:
enum day{Mon=1,Tue,Wed,Thu,Fri,Sat,Sun};
Means
Sun=7.
enum (enumeration) Data Type (CONTD….)
Example 4:
enum day{Mon=20,Tue,Wed,Thu,Fri,Sat,Sun};
26.
Means
Output:
WEEK START = 0
WEEK END = 6
enum (enumeration) Data Type (CONTD….)
Program Example 2:
#include<stdio.h>
void main()
{
enum day{mon=1,tue,wed,thu,fri,sat,sun};
enum day week_st, week_end;
week_st = mon;
week_end = sun;
if(week_st == tue)
{
week_end = sat;
}
printf(“WEEK START = %d\n”,week_st);
printf(“WEEK END = %d\n”,week_end);
}
enum (enumeration) Data Type (CONTD….)
Output:
WEEK START = 1
WEEK END = 7
enum (enumeration) Data Type (CONTD….)
Program Example 3:
#include<stdio.h>
void main()
{
enum MONTH{jan,feb,mar};
enum day month;
month = mar;
if(month == 0)
{ printf(“Month is January\n”); }
if(month == 1)
{ printf(“Month is February\n”); }
if(month == 2)
{ printf(“Month is March\n”); }
}
enum (enumeration) Data Type (CONTD….)
Output:
Month is March
enum (enumeration) Data Type (CONTD….)
Example:
enum day{mon,tue,wed,thu,fri,sat,sun}week_st,week_end;
Instead of
enum day{mon,tue,wed,thu,fri,sat,sun};
Syntax:
#define PASS_MARK 50
#define PI 3.14159
Defining Symbolic Constants (CONTD….)
signed
unsigned
long
short
Data Type Modifier (CONTD….)
signed int a;
Here, variable ‘a’ can store both positive and negative
values.
Data Type Modifier (CONTD….)
unsigned int a;
Here, variable ‘a’ can store only positive values.