Explain C code

Paste C and get its pointers, structs and memory explained in plain English before you compile.

players.c

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Google Gemini to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe25 lines selected

Press Explain it for the sample, or paste your own code first.

What this C sample shows

structs
typedef struct { ... } Player; defines a record with a 16-byte name and an int score, and lets you write Player instead of a full struct type.
manual memory
calloc reserves room for count players on the heap, and free(team) gives it back. Nothing frees it for you.
pointers
make_players returns a Player *, the address of the first player. team[1] is the second player, the same as *(team + 1).
the stack
team and players are local variables on the stack, but the players they point to live on the heap. That is why the players still exist after make_players returns.

Good to know

  • sizeof *players asks for the size of whatever players points to, so the line stays correct if its type changes.
  • calloc returns NULL when it can't allocate, including when count times the size of a player is too big for a size_t. Both functions check for that before touching the memory.
  • snprintf with sizeof players[i].name never writes past the 16-byte array. A longer name is cut short instead of overflowing into score.

Watch out: After free(team), team still holds the old address. Using it again, or calling free on it twice, is undefined behavior. Setting team = NULL right after freeing makes that mistake easier to catch.

Explain C code beside your editor

Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).