A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
A void function can contain return; with no value. It exits the function immediately. This is not an error. It is a feature. It is the mechanism for guard clauses in void functions: validate inputs at the top, return immediately on failure, and let the main logic proceed without nesting. A void function without an explicit return falls off the end, which is equivalent to return; at the closing brace.
#include <stdio.h>#include <string.h>void log_message(const char *level, const char *msg) {if (level == NULL) {fprintf(stderr, "Error: NULL level\n");return;}if (msg == NULL) {fprintf(stderr, "Error: NULL message\n");return;}if (strlen(msg) == 0) {return;}printf("[%s] %s\n", level, msg);}int main(void) {log_message("INFO", "Server started");log_message(NULL, "This fails");log_message("DEBUG", "");log_message("WARN", "Disk space low");return 0;}
Three guard clauses. Three early returns. The main logic, the printf, sits at the base indentation level. The empty message case returns silently, which is a valid design choice: empty messages are not errors, they are no-ops. The NULL cases report to stderr and return. The function never nests deeper than one level.
return; in a void function is the guard clause enabler. Use it to validate, to bail out, to keep your code flat and readable. The alternative, nested if-else pyramids, is where bugs hide. Next: local vs global variables, and why the default should always be local.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.