The number of tokens in the following C code segment is switch(inputvalue) {…
2020
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 159 students.
Show answer & explanation
Correct answer: C
To determine the number of tokens, identify each keyword, identifier, constant, operator, and punctuation mark. The code segment contains:
The total number of tokens is: 26
Explanation:
switch → 1
( → 2
inputvalue → 3
) → 4
{ → 5
case → 6
1 → 7
: → 8
b → 9
= → 10
c → 11
* → 12
d → 13
; → 14
break → 15
; → 16
default → 17
: → 18
b → 19
= → 20
b → 21
++ → 22
; → 23
break → 24
; → 25
} → 26
Total tokens = 26
A video solution is available for this question — log in and enroll to watch it.