Bird
0
0

Identify the error in this FreeRTOS idle hook implementation:

medium📝 Debug Q14 of 15
FreeRTOS - Task Scheduling

Identify the error in this FreeRTOS idle hook implementation:

void vApplicationIdleHook(void) {
    int count = 0;
    count++;
    if (count == 5) {
        // Do something
    }
}
AIdle hook function must return an int
Bcount should be declared static to retain its value
Ccount variable should be global
DIdle hook cannot use if statements
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable lifetime in idle hook

    The variable count is declared inside the function, so it resets to 0 every call.
  2. Step 2: Fix variable to retain value across calls

    Declaring count as static keeps its value between calls, allowing counting.
  3. Final Answer:

    count should be declared static to retain its value -> Option B
  4. Quick Check:

    Use static for persistent variables in idle hook [OK]
Quick Trick: Use static variables to keep count across idle hook calls [OK]
Common Mistakes:
  • Declaring count as local resets it every call
  • Expecting idle hook to return a value
  • Thinking global variable is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes