Code Room
Code reviewMedium
Question
Review this C function that reports a parsed header.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
#include <stdio.h> struct Header { int version; int flags; int length; }; struct Header parse(const unsigned char *buf, size_t n) { struct Header h; h.version = buf[0]; if (n > 4) { h.length = (buf[1] << 8) | buf[2]; } return h;} int main(void) { unsigned char data[2] = {1, 0}; struct Header h = parse(data, sizeof data); printf("flags=%d length=%d\n", h.flags, h.length);}Run or narrate your approach, then ask the coach.