Chapter 10

Fun with Functions

IN THIS CHAPTER

check Creating a function

check Avoiding the prototype

check Working with variables in a function

check Passing arguments to a function

check Returning values from a function

check Using return to leave a function

When it comes to getting work done, it’s a program’s functions that do the heavy lifting. The C language comes with libraries full of functions, which help bolster the basics of the language, the keywords, the operators, and so on. When these C library functions fall short, you concoct your own functions.

Anatomy of a Function

The tools that are needed to craft your own functions are brief. After deciding the function’s purpose, you give it a unique name, toss in some parentheses and curly brackets, and you’re pretty much done. Of course, the reality is a bit more involved.

Constructing a function

All functions are dubbed with a name, which must be unique; no ...

Get C Programming For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.