Question

A C function pop(Stack*
s) is designed to remove and return the top element from a stack. #include #include #define MAX_SIZE 10 typedef struct {     int arr[MAX_SIZE];     int top; } Stack; int pop(Stack*
s) {     // Assume stack is initialized with s->top = -1 for empty     return s->arr[s->top--]; // Potential bug here } If pop() is called on an empty stack (where s->top is -1), what is the most likely immediate consequence?

A The function will return a garbage value without crashing.
B The program will crash due to accessing invalid memory (segmentation fault).
C The s->top will become -2, leading to an overflow.
D The stack will correctly remain empty.
E A compile-time error will occur.
Practice Next

Hey! Ask a query