Bird
0
0

What will be the output of the following code snippet?

medium📝 Predict Output Q4 of 15
FreeRTOS - Memory Management
What will be the output of the following code snippet?
void *ptr = pvPortMalloc(50);
if(ptr != NULL) {
    vPortFree(ptr);
    printf("Memory freed\n");
} else {
    printf("Allocation failed\n");
}
AMemory freed
BAllocation failed
CCompilation error
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Analyze memory allocation and check pointer

    The code tries to allocate 50 bytes. If successful, ptr is not NULL.
  2. Step 2: Free memory and print message

    Since allocation likely succeeds, vPortFree(ptr); is called and "Memory freed" is printed.
  3. Final Answer:

    Memory freed -> Option A
  4. Quick Check:

    Successful allocation prints "Memory freed" [OK]
Quick Trick: Check ptr != NULL before freeing memory [OK]
Common Mistakes:
  • Assuming allocation always fails
  • Forgetting to check NULL before free
  • Confusing output messages

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes