0
0
Embedded Cprogramming~20 mins

Common embedded bugs and fixes in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Embedded C Mastery
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 embedded C code snippet?

Consider the following code running on an embedded system. What will be printed?

Embedded C
#include <stdio.h>

volatile int flag = 0;

void interrupt_handler() {
    flag = 1;
}

int main() {
    while (!flag) {
        // wait for interrupt
    }
    printf("Flag set!\n");
    return 0;
}
AFlag set!
BNo output (infinite loop)
CCompilation error due to volatile usage
DRuntime error due to interrupt_handler
Attempts:
2 left
💡 Hint

Think about the role of volatile in embedded systems.

Predict Output
intermediate
2:00remaining
What is the output of this pointer arithmetic code?

What will be printed by this embedded C code?

Embedded C
#include <stdio.h>

int main() {
    char buffer[5] = {1, 2, 3, 4, 5};
    char *p = buffer;
    printf("%d\n", *(p + 3));
    return 0;
}
A3
B5
C4
DCompilation error due to pointer usage
Attempts:
2 left
💡 Hint

Remember that pointer arithmetic moves by element size.

🔧 Debug
advanced
2:00remaining
What error does this code cause?

Analyze the following embedded C code. What error will it cause when run?

Embedded C
#include <stdio.h>

int main() {
    int *ptr = NULL;
    *ptr = 10;
    printf("%d\n", *ptr);
    return 0;
}
AUndefined behavior but no crash
BPrints 10
CCompilation error due to NULL pointer assignment
DSegmentation fault (null pointer dereference)
Attempts:
2 left
💡 Hint

Think about what happens when you write to a null pointer.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error?

Which of the following code snippets will cause a syntax error in embedded C?

A
int x = 10
int y = 20;
Bint *p = &arr[0];
Cvoid func() { return; }
Dint arr[5] = {1, 2, 3, 4, 5};
Attempts:
2 left
💡 Hint

Look for missing semicolons.

🚀 Application
expert
3:00remaining
How many bytes does this struct occupy?

Given the following struct on a 32-bit embedded system, how many bytes does it occupy?

Embedded C
struct Data {
    char a;
    int b;
    char c;
};
A8 bytes
B12 bytes
C9 bytes
D10 bytes
Attempts:
2 left
💡 Hint

Consider padding and alignment on a 32-bit system.