Ad space (banner)
๐Ÿ”งC Lessons
Lesson 6 / 68

Writing a Function

This lesson covers the basics of writing a function in C, so you can write code that's reused across many calls. It's for anyone searching "C function tutorial."

Define a function in the form return-type functionName(parameters) { }. Bundling logic you use often under a name means you can just call it whenever you need it.

The example's greet function takes a const char *name parameter and displays a greeting message. Notice using void when there's no return value.

A common early mistake is not seeing the difference between a function's declaration (a prototype) and its definition. A function needs to be defined before it's used, and not being conscious of the order can produce a compile error.

In real projects, bundling shared logic into a function reduces duplication and means a fix only needs to happen in one place.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)