C Function Basics

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Function Basics?

A function bundles statements under a name. It has a return type, a name, a parameter list, and a body. main is just a function that the runtime calls first. Use void when a function returns nothing.

Remember
return_type name(parameter_list) {
    /* body */
    return value;   /* omit for void */
}

void greet(const char *name);
int  add(int a, int b);

Cheat Sheet

Keep these facts handy while you work with Function Basics in C.

TopicDetail
No resultvoid return type
No parametersint f(void) (not int f())
Callf(args); or x = f(args);
NamingVerb-like names such as print_report

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Declaration and Definition.

Example 1 — A void function and a value-returning function

One function prints; the other computes.

C
#include <stdio.h>

void greet(const char *name) {
    printf("Hello, %s!\n", name);
}

int add(int a, int b) {
    return a + b;
}

int main(void) {
    greet("Ada");
    printf("2 + 3 = %d\n", add(2, 3));
    return 0;
}

How It Works

  1. greet returns void, so it is called as a statement.
  2. add returns an int, so the call is used inside an expression.
  3. Both functions are defined before main, so no prototypes are needed.

Edge Cases & Pitfalls

Check these before relying on Function Basics in real programs.

()

Empty parentheses

In C int f() means "unspecified parameters" in older standards. Write int f(void) for none.

ret

Missing return

A non-void function that ends without return gives an indeterminate value if the caller uses it.

Key Takeaways

  • Parts: type, name, parameters, body.
  • void: no return value.
  • Single job: keep functions small.

One line: A function bundles statements under a name.

Frequently Asked Questions

A function is a named, reusable block of code that can take parameters and return a value. Every C program has at least main.
Yes. A function can call any function that is declared before the call, including itself (recursion).
Continue with "C Declaration and Definition" next. Tell the compiler a function exists, then provide its body. The C Functions hub lists every topic in order.

Next: Declaration and Definition

Tell the compiler a function exists, then provide its body.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful