Your question is Embedded C Debugging and Output. Take a moment with it on the right.
Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).
AMD's embedded C interview loop likes to combine "what's wrong with this" with "what does it print" in the same snippet, since firmware bugs often compile cleanly and just produce quietly wrong numbers. Here is the snippet.
#include <stdio.h>
int classify(int value) {
int result;
if (value = 0) {
result = 1;
} else {
result = 0;
}
return result;
}
unsigned char accumulate(void) {
unsigned char total = 0;
for (unsigned char i = 0; i < 10; i++) {
total = total + 30;
}
return total;
}
int average_of_three(int a, int b, int c) {
return (a + b + c) / 3;
}
int main(void) {
printf("classify(5) = %d
", classify(5));
printf("classify(0) = %d
", classify(0));
printf("accumulate() = %u
", accumulate());
printf("average = %d
", average_of_three(7, 8, 8));
return 0;
}
What's wrong with this code, and what is the exact output when it runs? Explain each issue and trace through the program to give the precise printed values -- this compiles and runs without crashing, so you need to reason about what it actually produces, not just spot that something looks off.