Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The code that follows shows an example of branching on an enumerated type value

ID: 3735651 • Letter: T

Question

The code that follows shows an example of branching on an enumerated type value in a switch statement. Recall that enumerated types in C are simply a way to introduce a set of names having associated integer values. By default, the values assigned to the names go from zero upward. In our code, the actions associated with the different case labels have been omitted 1Enumerated type creates set of constants numbered 0 and upward / 2 typedef enum tMODE_A, MODE_B, MODE C, MODE D, MODEE mode_t; 4 long switch3(long *pl, long *p2, mode_t action) long result-0; switch (action) t case MODE A: case MODE B: case MODE C case MODE_D: case MODE E default 10 12 14 15 16 17 18 19 20 21 return result;

Explanation / Answer

Solution:

long result=0;

Switch(action)

{

MODE_A : swapping is occuring between two varibles; break;

MODE_B: similar kind of swapping as MODE_A is occuring between two varibles; break;

MODE_C: result = p1 ; p2=59; break;

MODE_D : fallthrough to E (*p1=*p2) ;break;

MODE_E : result = 27; break;

DEFAULT: result = 12

}