Multiple choice

What would be the output of the following?

main() { int i=strlen("Blue")+strlen("Purple")/strlen("Red")-strlen("Green"); printf("%d",i); }

  1. 0

  2. 3

  3. 2

  4. 1

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Operator precedence matters: division happens before addition/subtraction. strlen("Blue")=4, strlen("Purple")=6, strlen("Red")=3, strlen("Green")=5. So: 4 + 6/3 - 5 = 4 + 2 - 5 = 1.