Need Help or More Information?
Questions about this free C programming course, embedded C training or career guidance? Get in touch.
Types of Functions in C
Learn the four types of functions in C, based on arguments and return values, and master the first one: functions with no arguments and no return value. Part of our free C programming course.
Once you know how arguments go in and values come out, the types of functions in C fall into a neat classification of four. In this lecture of our free C programming course we introduce that classification, then study the simplest member in depth: the function that takes nothing and gives nothing back. This is the shape of most start-up routines and interrupt handlers, so it matters a great deal for C programming for embedded systems.
This free C tutorial keeps the style of the rest of our free embedded C course: short original programs, real output copied from a compiler run, and diagrams that show what is happening.
What You Will Learn
- The four types of functions in C and how to tell them apart at a glance
- How to declare, define and call a function with no arguments and no return value
- Why this kind of function cannot take part in an expression
- The difference between an empty parameter list and the keyword
void, including the change in the newest C standard - Where such functions appear in embedded firmware
- How all four types look side by side in one small program
Prerequisites
- Understanding of actual and formal arguments (previous lecture)
- Understanding of the return value of a function
- A working C compiler, preferably gcc with warnings enabled
The Four Types of Functions in C
Every function can be placed on two simple questions. Does it receive data through arguments? Does it send a result back through a return value? Two yes/no answers give four combinations, and each combination has a characteristic job.
| Type | Data in | Data out | Typical embedded job |
|---|---|---|---|
| 1 | none | none | init routine, toggle a pin, interrupt handler |
| 2 | none | one value | read a sensor or switch, get a configured constant |
| 3 | one or more | none | set a duty cycle, send a byte, print a message |
| 4 | one or more | one value | checksum, scaling, limiting, conversions |
This lecture takes Type 1 apart completely. The next lecture handles Type 2, and the following ones cover Types 3 and 4.
Functions With No Arguments and No Return Value
A Type 1 function is the closest thing C has to a plain command: you call it, it performs its job, and control comes back with nothing else exchanged. Both the parameter list and the return type are void. The general pattern looks like this:
void func(void); /* declaration (prototype) */
int main(void)
{
func(); /* call */
return 0;
}
void func(void) /* definition */
{
/* statements that do the work */
}
Because no argument is given, the caller cannot pass any data in. Because the return type is void, the function cannot report anything back. The caller and the function are connected only by the fact of the call. A direct consequence is that the call cannot be used as an operand, so something like x = func() + 1; is a compile error. You can only use it as a standalone statement.
A complete example: a start-up banner
Many devices print a short identity message on a debug port when they power up. That job needs no input and produces no result, so it is a perfect Type 1 function. The code below is original and was compiled and run before being published here.
#include <stdio.h>
static void print_boot_banner(void);
int main(void)
{
print_boot_banner();
printf("system ready\n");
return 0;
}
static void print_boot_banner(void)
{
puts("== Sensor Node v1.2 ==");
puts("clock : 16 MHz");
puts("mode : low power");
}
== Sensor Node v1.2 ==
clock : 16 MHz
mode : low power
system ready
Read the program in the order the CPU executes it. The prototype near the top promises the compiler that the function exists. The call in main transfers control, the three lines are printed, and the program resumes with system ready. The keyword static keeps the function private to this file, a good habit for helper routines that no other file needs.
Empty parentheses versus void
You will meet two ways of writing a parameter list with nothing in it: void tick(void) and void tick(). They are not identical before the newest standard. In the older rules, empty parentheses only mean that the parameter information is not specified, so the compiler does not check how many arguments a caller supplies. We tested this with a call that deliberately passes two values:
void tick();
int main(void)
{
tick(1, 2); /* wrong, but allowed by old rules */
return 0;
}
$ gcc -std=c11 tick.c -o tick && ./tick
tick
$ gcc -std=c2x tick.c -o tick
error: too many arguments to function 'tick'
With the C11 rules the wrong call compiles quietly, which hides a bug. With the newer C23 rules empty parentheses mean no parameters, so the same call becomes an error. The safe habit that works under every standard is to always write (void) when a function takes no arguments.
void func() in older code disables argument checking for that function. Use void func(void) everywhere in firmware so the compiler can protect you.Where This Type Shows Up in Embedded C Programming
| Function | Why no data is needed |
|---|---|
| Clock or peripheral init | configuration is fixed and lives inside the routine |
| Interrupt service routine | hardware calls it; nobody can supply arguments or receive a result |
| LED toggle or buzzer beep | one fixed action on one fixed pin |
| Menu or banner printing | text is constant; output goes to the screen or serial port |
Interrupt handlers deserve a note. On ARM Cortex-M devices the vector table stores the address of each handler, and the hardware jumps to it directly, so the handler must be a void function with no parameters. This is the clearest real-world reason to master Type 1 early.
All Four Types of Functions in C Side by Side
To prepare for the next lectures, here is a compact program in which each of the four types appears once. Do not worry about the details of the last two yet; just notice how the declarations differ.
#include <stdio.h>
static void led_toggle(void);
static int read_switch(void);
static void set_duty(int percent);
static int clamp(int value, int low, int high);
int main(void)
{
led_toggle();
if (read_switch() == 1)
puts("switch is pressed");
set_duty(40);
printf("clamp(130, 0, 100) = %d\n", clamp(130, 0, 100));
return 0;
}
static void led_toggle(void)
{
puts("led toggled");
}
static int read_switch(void)
{
return 1;
}
static void set_duty(int percent)
{
printf("duty set to %d%%\n", percent);
}
static int clamp(int value, int low, int high)
{
if (value < low)
return low;
if (value > high)
return high;
return value;
}
led toggled
switch is pressed
duty set to 40%
clamp(130, 0, 100) = 100
Common Mistakes and Troubleshooting
| Mistake | Symptom | Fix |
|---|---|---|
| Using a void function inside an expression | compile error about void value | call it as its own statement |
Writing func() instead of func(void) in the declaration | wrong calls compile silently in older standards | always write (void) |
| Forgetting the parentheses when calling | the call never happens, a warning may appear | write func(); not func; |
| Hiding data in global variables to feed a Type 1 function | hard-to-trace bugs | pass data through arguments when it varies |
| Missing prototype before the call | implicit declaration warnings or errors | declare the function above the first call |
Best Practices
- Give the function a verb-first name such as
print_boot_bannerorled_toggle. - Keep it to one job so its effect is easy to describe in a sentence.
- Use
staticfor helpers that do not belong to a public interface. - Put a short comment above the function listing any hardware it touches.
- If the function starts needing data that changes, promote it to a Type 3 function with parameters.
Performance: a call and return costs a few cycles, which is rarely an issue, though in a very hot loop a compiler may inline a tiny function for you. Security: functions that rely on hidden global state are harder to review, so prefer explicit inputs whenever the behaviour depends on external data.
Summary and Key Takeaways
- The types of functions in C are four: no args/no return, no args/return, args/no return and args/return.
- A no-argument, no-return function has no communication with its caller beyond the call itself.
- It cannot be used as an operand because it produces no value.
- Always write
(void)for an empty parameter list. - Interrupt handlers and init routines are classic Type 1 functions in embedded firmware.
Conclusion
You now have a map of the types of functions in C and a deep understanding of the first one. The classification is more than vocabulary: when you design a new routine, asking whether it needs input and whether it must report a result guides you to the right shape immediately. Type 1 functions are everywhere in firmware, from the first line of your start-up code to every interrupt handler. In the next lecture we study the second type, a function with no arguments that does return a value, and we will build a few original examples. Keep working through this free C programming course and compile everything with warnings on.
Frequently Asked Questions
How many types of functions are there in C?
Four, based on whether a function takes arguments and whether it returns a value.
Can I use a void function in an expression?
No. It produces no value, so it can only be called as a statement.
Is void func() the same as void func(void)?
In C11 and older, empty parentheses leave the parameters unspecified. In C23 they mean no parameters. Writing (void) is safe in all versions.
Why are interrupt handlers void functions without arguments?
The hardware jumps to them directly through the vector table, so there is nobody to pass data in or receive a result.
When should a function take arguments instead?
When its behaviour depends on data that changes from call to call, passing that data explicitly is clearer than using global variables.
Does a void function need a return statement?
No. It ends at the closing brace, though a bare return; may be used to leave early.
Keep Learning Embedded C Programming
The next lecture covers functions with no arguments that return a value. Continue the course or go back to the index page.
Need Help or More Information?
Questions about this free C programming course, embedded C training or career guidance? Get in touch.

1 Comment