Code Room
Code reviewMediumcr-g384
Subject Buffer overflowLevel Mid–Senior~18 minCommon in Algorithms & data structures interviewsIndustries Software development, Telecom

Question

Review this C function that builds a greeting string on the heap.

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.

Talk through your review
Code to reviewc
char *greet(const char *name) {    size_t n = strlen(name);    char *out = malloc(n);          // room for the name    sprintf(out, "Hi, %s!", name);  // write greeting    return out;}
Run or narrate your approach, then ask the coach.