C Declaration and Definition

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Declaration and Definition?

A declaration (prototype) states a function's name, parameter types, and return type. A definition supplies the body. A function may be declared many times but defined only once in the whole program.

Remember
int max_of(int a, int b);          /* declaration */

int max_of(int a, int b) {         /* definition  */
    return a > b ? a : b;
}

Cheat Sheet

Keep these facts handy while you work with Declaration and Definition in C.

TopicDetail
DeclarationEnds with ;, no body
DefinitionHas { } body, defined once
Parameter namesOptional in declarations
WhereDeclarations go in headers

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Function Calls.

Example 1 — Declare above main, define below

The declaration lets main call functions defined later.

C
#include <stdio.h>

int max_of(int a, int b);
int min_of(int, int);

int main(void) {
    printf("max: %d\n", max_of(8, 3));
    printf("min: %d\n", min_of(8, 3));
    return 0;
}

int max_of(int a, int b) { return a > b ? a : b; }
int min_of(int a, int b) { return a < b ? a : b; }

How It Works

  1. min_of(int, int); omits parameter names, which is allowed in declarations.
  2. Definitions appear after main but the declarations make the calls legal.
  3. Each function is defined exactly once.

Edge Cases & Pitfalls

Check these before relying on Declaration and Definition in real programs.

mismatch

Declaration and definition disagree

If the types differ you get a compile error (or undefined behavior across files). Keep them in sync through a shared header.

dup

Two definitions

Defining the same function in two .c files causes a linker error: multiple definition.

Key Takeaways

  • Declare: signature only.
  • Define: signature plus body.
  • Headers: share declarations between files.

One line: A declaration (prototype) states a function's name, parameter types, and return type.

Frequently Asked Questions

A declaration introduces the name and signature; a definition provides the body. You can declare many times, but you must define once.
No. Types are enough, but names make headers self-documenting.
Continue with "C Function Calls" next. Invoke a function with arguments and use its result. The C Functions hub lists every topic in order.

Next: Function Calls

Invoke a function with arguments and use its result.

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.

9 people found this page helpful