C Example: Generic Container: void* payloads with print callbacks
Designs a Box struct with a const void* data field and a print function pointer. Stores int, double and string values in one array, each item carrying its own printer, and iterates calling the callback to print correctly. Demonstrates the classic void* type erasure plus callback type recovery.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
[0] int:42 [1] double:3.14 [2] text:C strings [3] int:42 sizes: int=4 double=8 ptr=8
🧩 Keep Learning