Enumeration is a process of

2012

Enumeration is a process of

Answer: C. Assigning the legal values possible for a variableConcept: an enumeration (an enumerated type) is a user-defined type whose definition names, one by one, the values that a variable of that type is intended to…

  1. A.

    Declaring a set of numbers

  2. B.

    Sorting a list of strings

  3. C.

    Assigning the legal values possible for a variable

  4. D.

    Sequencing a list of operators

Attempted by 9 students.

Show answer & explanation

Correct answer: C

Concept: an enumeration (an enumerated type) is a user-defined type whose definition names, one by one, the values that a variable of that type is intended to take. Each name introduced this way becomes a compile-time integer constant, so the purpose of the construct is to spell out and label the legal values of a variable — it does not reserve numeric storage, reorder data, or decide how an expression is evaluated.

Application: the C declaration enum color { RED, GREEN, BLUE }; makes the idea concrete.

  1. enum color { RED, GREEN, BLUE }; introduces a new type named enum color and, in the same declaration, the three enumeration constants RED, GREEN and BLUE.

  2. Because no explicit initialisers are written, the constants take consecutive values starting at zero: RED is 0, GREEN is 1 and BLUE is 2.

  3. The declaration enum color c; then creates a variable c of that type, and the values it is intended to range over are exactly the three names written into the type.

  4. Testing c against those names — for example if (c == GREEN) — is meaningful precisely because the type already spelled out which values c is meant to take.

  5. A point of precision: C implements an enumerated type over a compatible integer type, so storing a value outside the named list is not rejected at run time; the enumeration states the intended legal value set that readers and switch diagnostics rely on, rather than a constraint the language checks.

  6. What the declaration performed is therefore the fixing of the legal values possible for a variable, which is what enumeration means: assigning the legal values possible for a variable.

Cross-check: naming what each of the other described processes actually corresponds to in C shows that none of them names the value set of a type.

Process described

What it actually is in C

Declaring a set of numbers

An object declaration such as int a, b; or double t[5]; — it reserves typed storage, and no named value set is attached to the type.

Sorting a list of strings

A run-time rearrangement of data, performed by qsort with a strcmp-based comparator over an array of char *.

Sequencing a list of operators

Settled by the precedence and associativity rules of the language: in a + b * c the multiplication is applied before the addition.

Result: enumeration is the process of assigning the legal values possible for a variable.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…