Bird
0
0

Given the code:

medium📝 Predict Output Q5 of 15
FreeRTOS - Task Creation and Management
Given the code:
BaseType_t res = xTaskCreate(
  vTask, "T2", 500, NULL, 5, NULL);
if(res == pdPASS) printf("Success\n"); else printf("Fail\n");

What will be printed if the system runs out of heap memory?
ACompilation error
BSuccess
CFail
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand heap memory impact on task creation

    If the system heap is exhausted, xTaskCreate() cannot allocate stack and control structures, so it fails.
  2. Step 2: Check return value on failure

    On failure, xTaskCreate() returns pdFAIL, so "Fail" is printed.
  3. Final Answer:

    Fail -> Option C
  4. Quick Check:

    Heap exhaustion causes pdFAIL = "Fail" [OK]
Quick Trick: No heap memory means xTaskCreate returns pdFAIL [OK]
Common Mistakes:
  • Assuming NULL task handle causes failure
  • Thinking success prints even on failure
  • Ignoring heap memory limits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes