The number of tokens in the following C code segment is switch (inputvalue) {…
2025
The number of tokens in the following C code segment is
switch (inputvalue)
{
case 1 : b = c * d ; break ;
default : b = b++ ; break ;
}
- A.
27
- B.
29
- C.
26
- D.
24
Attempted by 54 students.
Show answer & explanation
Correct answer: C
To count tokens, identify keywords like switch and case, identifiers like inputvalue, operators such as = and *, punctuation including braces and semicolons, and constants. Counting each distinct element sequentially in the provided code segment yields a total of 26 tokens.