Stack, Queue, and Function Pointers
Filed under Qualcomm
Free read 3 of 3Define Stack as LIFO (Last In, First Out) with push/pop operations, and Queue as FIFO (First In, First Out) with enqueue/dequeue operations.
The question
Answer conceptual questions regarding Stacks and Queues, and write a code snippet demonstrating the declaration and usage of function pointers in C/C++.
Constraints
- Must use standard C or C++ syntax for function pointers.
Approach
Define Stack as LIFO (Last In, First Out) with push/pop operations, and Queue as FIFO (First In, First Out) with enqueue/dequeue operations.
Explain that a function pointer points to code rather than data, allowing callback mechanisms or dynamic function selection.
Write a clean example defining a simple math function, declaring a pointer to it, and invoking it via the pointer.
Handling null function pointers and ensuring correct function signatures.
Solution
O(1) time, O(1) space
def add(a, b):
return a + b
# Simulating function pointer behavior in Python
func_ptr = add
assert func_ptr(2, 3) == 5
Tips
- What they are testing: Tests fundamental data structure knowledge (LIFO vs FIFO) and low-level language fluency with function pointers.
- Common mistake: Incorrect syntax when declaring a function pointer, such as missing parentheses around the pointer variable name.
Follow-ups
- Basic questions on stack and queue.
- Write code snippet for function pointers.
Related Qualcomm questions
Collected from public candidate posts and coding forums. Updated Nov 2026.