Bird
0
0

Consider the following FreeRTOS code snippet:

medium📝 Predict Output Q13 of 15
FreeRTOS - Memory Management
Consider the following FreeRTOS code snippet:
void *ptr = pvPortMalloc(100);
if(ptr != NULL) {
    vPortFree(ptr);
    ptr = NULL;
}
printf("%p", ptr);

What will be the output of the printf statement?
AA memory address (non-NULL pointer)
BCompilation error
CNULL (0x0 or equivalent)
DRandom garbage value
Step-by-Step Solution
Solution:
  1. Step 1: Analyze memory allocation and freeing

    pvPortMalloc(100) allocates memory and returns a pointer. Then vPortFree(ptr) frees it, and ptr is set to NULL.
  2. Step 2: Understand the printf output

    Since ptr is explicitly set to NULL, printf will print 0x0 or equivalent NULL pointer representation.
  3. Final Answer:

    NULL (0x0 or equivalent) -> Option C
  4. Quick Check:

    Pointer set to NULL after free = NULL output [OK]
Quick Trick: Pointer set to NULL after free prints NULL [OK]
Common Mistakes:
  • Assuming pointer still holds address after free
  • Expecting compilation error due to free
  • Thinking printf prints garbage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes