0
0
Simulinkdata~20 mins

Generated C code inspection in Simulink - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Generated C Code Inspection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple generated C function
What is the output of the following generated C code snippet when input = 5?
Simulink
int generated_function(int input) {
    int output = 0;
    for (int i = 0; i < input; i++) {
        output += i * 2;
    }
    return output;
}

int main() {
    int result = generated_function(5);
    printf("%d", result);
    return 0;
}
A20
B30
C40
D50
Attempts:
2 left
💡 Hint
Sum the values of i*2 for i from 0 to 4.
data_output
intermediate
2:00remaining
Inspecting array output from generated code
What is the content of the array output after running this generated C code?
Simulink
void generated_array(int input, int output[]) {
    for (int i = 0; i < input; i++) {
        output[i] = i * i;
    }
}

int main() {
    int output[4];
    generated_array(4, output);
    for (int i = 0; i < 4; i++) {
        printf("%d ", output[i]);
    }
    return 0;
}
A1 4 9 16
B0 2 4 6
C0 1 4 9
D0 1 2 3
Attempts:
2 left
💡 Hint
Each element is the square of its index.
🔧 Debug
advanced
2:00remaining
Identify the error in generated C code snippet
What error will this generated C code produce when compiled?
Simulink
int generated_error(int input) {
    int output;
    if (input > 0)
        output = input * 2;
    return output;
}

int main() {
    int result = generated_error(0);
    printf("%d", result);
    return 0;
}
ANo error, prints 0
BSyntax error: missing semicolon
CType error: incompatible types
DUse of uninitialized variable 'output'
Attempts:
2 left
💡 Hint
Consider what happens when input is 0.
🧠 Conceptual
advanced
1:30remaining
Understanding memory layout in generated C code
In generated C code, which memory segment typically stores global variables?
AData segment
BStack segment
CHeap segment
DCode segment
Attempts:
2 left
💡 Hint
Globals are stored separately from local variables and dynamic memory.
🚀 Application
expert
2:30remaining
Analyzing performance impact of generated C code loop unrolling
Given this generated C code with loop unrolling, what is the main benefit compared to a simple loop?
Simulink
void generated_unrolled(int *arr, int n) {
    for (int i = 0; i < n; i += 4) {
        arr[i] = arr[i] * 2;
        arr[i+1] = arr[i+1] * 2;
        arr[i+2] = arr[i+2] * 2;
        arr[i+3] = arr[i+3] * 2;
    }
}
AAutomatically parallelizes code across multiple CPU cores
BReduces loop overhead and increases instruction-level parallelism
CDecreases code size significantly
DEliminates the need for array bounds checking
Attempts:
2 left
💡 Hint
Think about how fewer loop iterations affect CPU instructions.