C Function Prototypes

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Function Prototypes?

A prototype is a declaration that lists the return type and parameter types. It lets the compiler check every call. Without one, old C assumes the function returns int, and C99 and later treat the missing declaration as an error or warning.

Remember
double power(double base, int exp);   /* prototype */
int    main(void);
void   log_msg(const char *msg);

Cheat Sheet

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

TopicDetail
PlaceTop of file or in a header
No parametersvoid f(void);
ChecksArgument count and types
GuardPair with header guards

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Pass by Value.

Example 1 — Prototype for a function defined later

The call compiles cleanly because the prototype comes first.

C
#include <stdio.h>

int cube(int n);

int main(void) {
    printf("cube(3) = %d\n", cube(3));
    return 0;
}

int cube(int n) {
    return n * n * n;
}

How It Works

  1. The prototype appears before main.
  2. The compiler checks cube(3) against int cube(int n).
  3. The definition can live anywhere later, or in another file.

Edge Cases & Pitfalls

Check these before relying on Function Prototypes in real programs.

implicit

Implicit declaration

Calling an undeclared function is an error in C99+. GCC warns with -Wall.

empty

Using f() instead of f(void)

int f(); disables parameter checking in older C. Use (void) for no parameters.

Key Takeaways

  • Order: declare before use.
  • Types: prototypes enable argument checks.
  • Reuse: put them in headers.

One line: A prototype is a declaration that lists the return type and parameter types.

Frequently Asked Questions

In C99 and later every function must be declared before it is called. A prototype is the standard way to do that.
In a header file included by both the definition and the callers, so they stay consistent.
Continue with "C Pass by Value" next. C copies arguments, so changes inside a function do not reach the caller. The C Functions hub lists every topic in order.

Next: Pass by Value

C copies arguments, so changes inside a function do not reach the caller.

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