0% found this document useful (0 votes)
2 views

PROGRAM FOR ENUMS

The document explains a C program that demonstrates the use of enums, specifically defining an enum type called 'Company' with constants for various companies. It details the program structure, including include statements, enum declaration, and the main function where enum variables are printed. The output shows the integral values assigned to the enum constants, with 'XEROX' as 2, 'GOOGLE' as 0, and 'EBAY' as 4.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PROGRAM FOR ENUMS

The document explains a C program that demonstrates the use of enums, specifically defining an enum type called 'Company' with constants for various companies. It details the program structure, including include statements, enum declaration, and the main function where enum variables are printed. The output shows the integral values assigned to the enum constants, with 'XEROX' as 2, 'GOOGLE' as 0, and 'EBAY' as 4.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM FOR ENUMS:

#include <stdio.h>

#include <stdlib.h>

int main()

enum Company { GOOGLE, FACEBOOK, XEROX, YAHHOO, EBAY, MICROSOFT } ;

enum Company xerox = XEROX;

enum Company google = GOOGLE;

enum Company ebay = EBAY;

printf("The value of xerox is: %d\n", xerox);

printf("The value of google is: %d\n", google);

printf("The value of ebay is: %d\n", ebay);

return 0;

EXPLANATION OF ABOVE PROGRAM:

This program demonstrates the use of enums in C. Enums, short for enumerations, allow you to define a set of
named integral constants. In this program, an enum type called `Company` is defined with several constants
representing different companies.

Here's a breakdown of the program:

1. **Include Statements**:

```c

#include <stdio.h>

#include <stdlib.h>

```

These are include statements to include the standard input/output and standard library header files.

2. **Enum Declaration**:

```c

enum Company { GOOGLE, FACEBOOK, XEROX, YAHHOO, EBAY, MICROSOFT };

```
This declares an enumeration type `Company` with the constants `GOOGLE`, `FACEBOOK`, `XEROX`, `YAHHOO`,
`EBAY`, and `MICROSOFT`. By default, these constants are assigned integral values starting from 0 and incrementing
by 1 for each subsequent constant (i.e., `GOOGLE` is 0, `FACEBOOK` is 1, and so on).

3. **Main Function**:

```c

int main()

// Enum variable declarations

enum Company xerox = XEROX;

enum Company google = GOOGLE;

enum Company ebay = EBAY;

// Print the values of enum variables

printf("The value of xerox is: %d\n", xerox);

printf("The value of google is: %d\n", google);

printf("The value of ebay is: %d\n", ebay);

return 0;

```

- Three variables `xerox`, `google`, and `ebay` are declared of type `enum Company`, and they are assigned values
from the `Company` enum constants `XEROX`, `GOOGLE`, and `EBAY`, respectively.

- Then, the program prints out the integral values of these variables using `printf()`.

4. **Output**:

The output of this program will be:

```

The value of xerox is: 2

The value of google is: 0

The value of ebay is: 4

```

These values correspond to the integral values assigned to the enum constants `XEROX`, `GOOGLE`, and `EBAY`,
respectively.

You might also like