Bird
Raised Fist0
Embedded Cprogramming~20 mins

Interrupt vector table in Embedded C - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Interrupt Vector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this interrupt vector table initialization?

Consider this embedded C code snippet initializing an interrupt vector table. What will be the output when the reset_handler is called?

Embedded C
#include <stdio.h>

void reset_handler() {
    printf("System Reset\n");
}

void nmi_handler() {
    printf("NMI Interrupt\n");
}

void (* const interrupt_vector_table[])(void) = {
    reset_handler,  // Reset vector
    nmi_handler     // NMI vector
};

int main() {
    interrupt_vector_table[0]();
    return 0;
}
ANMI Interrupt
BRuntime error: segmentation fault
CSystem Reset
DCompilation error due to missing semicolon
Attempts:
2 left
💡 Hint

Look at which function is called from the vector table index 0.

🧠 Conceptual
intermediate
1:30remaining
Which statement correctly describes the interrupt vector table?

Choose the correct description of an interrupt vector table in embedded systems.

AIt stores addresses of interrupt service routines and is used by the processor to jump to the correct handler.
BIt is a table that holds the priority levels of interrupts but not their addresses.
CIt is a memory area where all interrupt data is stored during execution.
DIt is a list of all interrupts that have occurred since system start.
Attempts:
2 left
💡 Hint

Think about what the processor needs to do when an interrupt occurs.

🔧 Debug
advanced
2:00remaining
What error occurs in this interrupt vector table declaration?

Examine the following code snippet. What error will occur when compiling?

Embedded C
void reset_handler(void) {}
void nmi_handler(void) {}

void (*interrupt_vector_table[])(void) = {
    reset_handler,
    nmi_handler,
};
AError: incompatible types in assignment to function pointer array.
BError: missing 'const' qualifier for the vector table pointer.
CError: trailing comma in the initializer list is not allowed in C.
DNo error; code compiles successfully.
Attempts:
2 left
💡 Hint

Check if trailing commas are allowed in array initializers in C.

❓ Predict Output
advanced
2:00remaining
What is the output of this vector table with a default handler?

Given this embedded C code with a default interrupt handler, what will be printed when interrupt_vector_table[2]() is called?

Embedded C
#include <stdio.h>

void reset_handler() {
    printf("Reset Handler\n");
}

void default_handler() {
    printf("Default Interrupt Handler\n");
}

void (* const interrupt_vector_table[])(void) = {
    reset_handler,
    default_handler,
    default_handler
};

int main() {
    interrupt_vector_table[2]();
    return 0;
}
AReset Handler
BDefault Interrupt Handler
CSegmentation fault at runtime
DCompilation error: initializer list size mismatch
Attempts:
2 left
💡 Hint

Look at the function pointer at index 2 in the vector table.

🚀 Application
expert
1:30remaining
How many entries are in this interrupt vector table array?

Given this embedded C code snippet, how many entries does the interrupt_vector_table array contain?

Embedded C
void reset_handler(void) {}
void nmi_handler(void) {}
void hard_fault_handler(void) {}

void (* const interrupt_vector_table[])(void) = {
    reset_handler,
    nmi_handler,
    hard_fault_handler
};
A3
B2
C4
D1
Attempts:
2 left
💡 Hint

Count the number of functions listed inside the initializer braces.

Practice

(1/5)
1.

What is the main purpose of an interrupt vector table in embedded C programming?

easy
A. To store global variables for the program
B. To link interrupt events to their handler functions
C. To manage memory allocation dynamically
D. To perform arithmetic operations automatically

Solution

  1. Step 1: Understand the role of interrupt vector table

    The interrupt vector table is a special array that holds addresses of interrupt handler functions.
  2. Step 2: Identify its purpose in program flow

    When an interrupt occurs, the processor uses this table to jump to the correct handler automatically.
  3. Final Answer:

    To link interrupt events to their handler functions -> Option B
  4. Quick Check:

    Interrupt vector table = links interrupts to handlers [OK]
Hint: Interrupt vector table connects interrupts to handlers [OK]
Common Mistakes:
  • Thinking it stores variables
  • Confusing with memory management
  • Assuming it performs calculations
2.

Which of the following is the correct way to declare an interrupt vector table as an array of function pointers in embedded C?

void (*interrupt_vector_table[])(void) = {
easy
A. void interrupt_vector_table(void) = {handler1, handler2};
B. int interrupt_vector_table[] = {handler1, handler2};
C. void (*interrupt_vector_table[])(void) = {handler1, handler2};
D. void *interrupt_vector_table = {handler1, handler2};

Solution

  1. Step 1: Recognize function pointer array syntax

    Function pointers to void functions with no parameters are declared as void (*name[])(void).
  2. Step 2: Match declaration with initialization

    void (*interrupt_vector_table[])(void) = {handler1, handler2}; correctly declares an array of such pointers and initializes it with handler functions.
  3. Final Answer:

    void (*interrupt_vector_table[])(void) = {handler1, handler2}; -> Option C
  4. Quick Check:

    Function pointer array syntax = void (*interrupt_vector_table[])(void) = {handler1, handler2}; [OK]
Hint: Function pointer arrays use void (*name[])(void) syntax [OK]
Common Mistakes:
  • Using int type instead of function pointers
  • Declaring as a single function, not array
  • Using void* without function pointer cast
3.

Given the following code snippet, what will be the output when the interrupt at index 1 occurs?

void handler0(void) { printf("Handler 0 called\n"); }
void handler1(void) { printf("Handler 1 called\n"); }
void (*interrupt_vector_table[])(void) = {handler0, handler1};

// Simulate interrupt 1
interrupt_vector_table[1]();
medium
A. Handler 1 called
B. Handler 0 called
C. No output, runtime error
D. Compilation error

Solution

  1. Step 1: Identify the function called by interrupt_vector_table[1]

    Index 1 points to handler1, which prints "Handler 1 called".
  2. Step 2: Understand the output of the function call

    Calling interrupt_vector_table[1]() executes handler1, printing the message.
  3. Final Answer:

    Handler 1 called -> Option A
  4. Quick Check:

    interrupt_vector_table[1]() calls handler1 [OK]
Hint: Index 1 calls handler1, prints its message [OK]
Common Mistakes:
  • Confusing index 0 and 1
  • Expecting no output or error
  • Misreading function pointer call syntax
4.

Consider this interrupt vector table declaration:

void handlerA(void) { /* ... */ }
void handlerB(void) { /* ... */ }

void (*interrupt_vector_table[])(void) = {handlerA, handlerB};

// Somewhere else in code
interrupt_vector_table[2]();

What is the problem here?

medium
A. Index 2 is out of bounds, causing undefined behavior
B. handlerB is not a valid function pointer
C. interrupt_vector_table must be declared as int array
D. No problem, code runs fine

Solution

  1. Step 1: Check the size of interrupt_vector_table

    The array has 2 elements at indices 0 and 1 only.
  2. Step 2: Analyze the call to interrupt_vector_table[2]()

    Index 2 is outside the array bounds, leading to undefined behavior or crash.
  3. Final Answer:

    Index 2 is out of bounds, causing undefined behavior -> Option A
  4. Quick Check:

    Accessing beyond array size = out of bounds error [OK]
Hint: Array indices start at 0; index 2 is invalid here [OK]
Common Mistakes:
  • Assuming array auto-expands
  • Thinking handlerB is invalid
  • Ignoring out-of-bounds errors
5.

You want to add a new interrupt handler handler2 to an existing vector table with 2 handlers. Which is the correct way to update the vector table to include handler2 at index 2?

void handler0(void) { /* ... */ }
void handler1(void) { /* ... */ }
void handler2(void) { /* ... */ }

// Existing vector table
void (*interrupt_vector_table[])(void) = {handler0, handler1};

// How to add handler2 correctly?
hard
A. No need to add; interrupts beyond index 1 are ignored
B. Assign handler2 directly: interrupt_vector_table[2] = handler2;
C. Use a pointer cast to add handler2 at index 2
D. Redefine the vector table with all three handlers: {handler0, handler1, handler2}

Solution

  1. Step 1: Understand array size fixed at declaration

    Arrays in C have fixed size; you cannot add elements dynamically.
  2. Step 2: Update vector table by redefining with all handlers

    To include handler2, redefine the array with three elements: {handler0, handler1, handler2}.
  3. Final Answer:

    Redefine the vector table with all three handlers: {handler0, handler1, handler2} -> Option D
  4. Quick Check:

    Arrays fixed size; redefine to add elements [OK]
Hint: Arrays fixed size; redefine to add handlers [OK]
Common Mistakes:
  • Trying to assign beyond array size
  • Using pointer casts unsafely
  • Assuming interrupts beyond defined handlers work
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard