0
0
Embedded Cprogramming~10 mins

Stack vs heap in embedded context - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a local variable on the stack.

Embedded C
void func() {
    int [1] = 10;
}
Drag options to blanks, or click blank then click option'
Alocal_var
Bheap_var
Cglobal_var
Dstatic_var
Attempts:
3 left
💡 Hint
Common Mistakes
Using global or static variable names instead of local.
2fill in blank
medium

Complete the code to allocate memory dynamically on the heap.

Embedded C
int* ptr = (int*) [1](sizeof(int));
Drag options to blanks, or click blank then click option'
Aalloc
Bmalloc
Cstackalloc
Dnew
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' which is C++ syntax, or 'alloc' which is incorrect.
3fill in blank
hard

Fix the error in the code to correctly free heap memory.

Embedded C
int* ptr = malloc(sizeof(int));
// ... use ptr
[1](ptr);
Drag options to blanks, or click blank then click option'
Arelease
Bdelete
Cdispose
Dfree
Attempts:
3 left
💡 Hint
Common Mistakes
Using C++ keywords like 'delete' or incorrect functions like 'dispose'.
4fill in blank
hard

Fill both blanks to create a stack-allocated array and access its first element.

Embedded C
int arr[[1]];
arr[[2]] = 5;
Drag options to blanks, or click blank then click option'
A10
B0
C5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the first index or invalid array sizes.
5fill in blank
hard

Fill all three blanks to allocate, assign, and free heap memory correctly.

Embedded C
int* ptr = [1](sizeof(int));
*ptr = [2];
[3](ptr);
Drag options to blanks, or click blank then click option'
Amalloc
B42
Cfree
Dnew
Attempts:
3 left
💡 Hint
Common Mistakes
Using C++ keywords or forgetting to free memory.