Bird
0
0

Given the following FreeRTOS code snippet, what will be the output printed by the consumer task?

medium📝 Predict Output Q4 of 15
FreeRTOS - Design Patterns for RTOS

Given the following FreeRTOS code snippet, what will be the output printed by the consumer task?

QueueHandle_t queue = xQueueCreate(2, sizeof(int));
int data = 10;
xQueueSend(queue, &data, 0);
data = 20;
xQueueSend(queue, &data, 0);
int received;
xQueueReceive(queue, &received, 0);
printf("%d\n", received);
xQueueReceive(queue, &received, 0);
printf("%d\n", received);

A10\n10
B20\n10
C10\n20
D20\n20
Step-by-Step Solution
Solution:
  1. Step 1: Analyze queue send order

    First, 10 is sent, then 20 is sent to the queue in that order.
  2. Step 2: Analyze queue receive order

    Queue is FIFO, so first receive gets 10, second gets 20.
  3. Final Answer:

    10\n20 -> Option C
  4. Quick Check:

    Queue order = FIFO = 10 then 20 [OK]
Quick Trick: FreeRTOS queues are FIFO, first sent is first received [OK]
Common Mistakes:
  • Assuming LIFO order instead of FIFO
  • Mixing up variable values after sending
  • Expecting both receives to return the same value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FreeRTOS Quizzes