Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q4 of 15
FreeRTOS - Task Creation and Management

What will be the output of this code snippet?

TaskHandle_t xHandle = NULL;
void vTaskCode(void * pvParameters) {
for(;;) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
int main() {
xTaskCreate(vTaskCode, "Task1", 1000, NULL, 1, &xHandle);
if(xHandle != NULL) {
printf("Task created successfully\n");
} else {
printf("Task creation failed\n");
}
return 0;
}

ANo output, program hangs
BTask created successfully
CCompilation error due to missing return
DTask creation failed
Step-by-Step Solution
Solution:
  1. Step 1: Understand xTaskCreate behavior

    xTaskCreate returns pdPASS and sets xHandle to the created task's handle if successful.
  2. Step 2: Check condition on xHandle

    Since xHandle is assigned a valid handle, it is not NULL, so the success message prints.
  3. Final Answer:

    Task created successfully -> Option B
  4. Quick Check:

    Task handle not NULL means success [OK]
Quick Trick: Check task handle for NULL to confirm creation [OK]
Common Mistakes:
  • Assuming handle stays NULL
  • Ignoring return value of xTaskCreate
  • Confusing delay with output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes