100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

Functions in C

Learn C functions: declaration vs definition, parameters, pass-by-value, return statements, and prototypes with examples.

Functions & RecursionBeginner14 min readJul 7, 2026
Analogies

1. Introduction

A function in C is a self-contained block of code that performs a specific task and can be called (invoked) from other parts of a program. Functions let you break a large program into smaller, reusable, and testable pieces. C programs are built from functions — every C program has at least one, main(), which is where execution begins. Beyond main(), you can write your own functions to avoid repeating code, to organize logic into named units, and to make programs easier to read, debug, and maintain.

🏏

Cricket analogy: A bowler's specific delivery, like Bumrah's yorker, is a reusable skill drilled separately from the match itself; main() is the innings where every skill gets called into action to complete the game.

Functions in C fall into two categories: library functions (predefined functions such as printf(), scanf(), strlen(), and sqrt() that come with the C Standard Library and are declared in header files like stdio.h, string.h, and math.h) and user-defined functions (functions that you write yourself to perform tasks specific to your program). This lesson focuses on user-defined functions — how to declare, define, call, and pass data to and from them.

🏏

Cricket analogy: printf() is like using a standard-issue Kookaburra bat everyone trusts, already manufactured and ready; a user-defined function is like a custom bat Steve Smith has specially crafted to his own grip and stroke.

2. Syntax

c
/* Function prototype (declaration) */
returnType functionName(parameterType1 param1, parameterType2 param2, ...);

/* Function definition */
returnType functionName(parameterType1 param1, parameterType2 param2, ...)
{
    /* function body */
    /* ... statements ... */
    return value;   /* omitted if returnType is void */
}

/* Function call */
functionName(argument1, argument2);

A function's signature consists of its return type, its name, and the types (and optionally names) of its parameters. The return type specifies what kind of value the function sends back to the caller; use void if the function returns nothing.

🏏

Cricket analogy: A bowler's action signature — pace, arm angle, and delivery type — identifies them, like Rashid Khan's leg-spin; a function's signature identifies its return type and parameter types the same way, with void meaning no scorecard entry.

3. Explanation

3.1 Declaration vs. Definition

A function declaration (also called a prototype) tells the compiler the function's name, return type, and parameter types WITHOUT providing the body. It ends with a semicolon: int add(int a, int b);. A function definition provides the actual body of the function — the code that executes when the function is called: int add(int a, int b) { return a + b; }. In small single-file programs you can define a function before main() and skip a separate prototype, but in larger programs, prototypes are placed near the top of the file (or in a header file) so that functions can be called before their full definition appears later in the file, or from other source files entirely.

🏏

Cricket analogy: A team sheet announcing Rohit Sharma will open the batting is like a prototype — it names the player and role without showing the actual innings; the definition is Rohit walking out and playing the full innings.

3.2 Why Prototypes Matter

Without a prototype, if you call a function before the compiler has seen its definition, older compilers assumed an implicit int return type — a dangerous, non-standard behavior that C99 and later standards disallow, producing a compile error instead. Always declare a prototype (or define the function) before it is first called. Prototypes also let the compiler perform type checking on arguments, catching mismatched-type bugs at compile time rather than causing undefined behavior at runtime.

🏏

Cricket analogy: Fielding a batter without checking the team sheet first, like assuming any padded-up player is the designated opener, risks fielding the wrong strategy; modern rules require confirming the lineup before play, just as C99 requires a prototype before calling.

3.3 Parameters vs. Arguments

A parameter is the variable listed in the function's definition/declaration (a placeholder). An argument is the actual value supplied when the function is called. In int add(int a, int b), 'a' and 'b' are parameters; in add(5, 3), 5 and 3 are arguments. C requires the number and (compatible) types of arguments to match the parameters, since C does not support default argument values or function overloading the way C++ does — every function call must supply exactly the arguments the prototype demands.

🏏

Cricket analogy: In a coaching drill, "batter faces bowler_type" is a parameter — a placeholder role; when Kohli actually faces Starc in a real match, that specific pairing is the argument supplied at call time.

3.4 Pass-by-Value Semantics

C passes all arguments by value: when you call a function, the function receives a COPY of each argument's value, not the original variable. Any changes the function makes to its parameters have no effect on the caller's original variables. This is why a function like void increment(int x) { x = x + 1; } does not change the variable passed to it — 'x' inside the function is a separate copy in its own stack frame.

🏏

Cricket analogy: Handing a scorer a photocopy of the scorecard to annotate during review doesn't change the official scorebook; similarly, a function receiving a copy of a value can scribble on it without altering the caller's original variable.

C has NO pass-by-reference mechanism (unlike C++, which offers reference parameters with &). To let a function modify a caller's variable, you must explicitly pass a pointer to that variable (its address, using &) and have the function dereference the pointer (using *) to read or write the original value. Forgetting this is one of the most common beginner bugs — writing void swap(int a, int b) and expecting it to swap the caller's variables will silently fail because 'a' and 'b' are only local copies.

c
#include <stdio.h>

/* WRONG: pass-by-value cannot swap the caller's variables */
void swapWrong(int a, int b) {
    int temp = a;
    a = b;
    b = temp;
}

/* CORRECT: pass addresses, modify via pointers */
void swapCorrect(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main(void) {
    int x = 10, y = 20;

    swapWrong(x, y);
    printf("After swapWrong: x=%d, y=%d\n", x, y);   /* unchanged */

    swapCorrect(&x, &y);
    printf("After swapCorrect: x=%d, y=%d\n", x, y);  /* swapped */

    return 0;
}

3.5 The return Statement

The return statement ends a function's execution and optionally sends a value back to the caller. Its type must match (or be convertible to) the function's declared return type. A function declared void must not return a value (a bare return; is allowed to exit early). A function can have multiple return statements along different code paths, but execution stops at whichever one runs first. If a non-void function reaches its closing brace without hitting a return, the returned value is undefined — always ensure every path returns a value.

🏏

Cricket analogy: A batter's dismissal ends their innings and reports a final score back to the scoreboard, like Kohli's 82; a non-out declaration is like void, ending without a number, but forgetting to record any score at all leaves the scoreboard undefined.

Tip: Keep functions short and focused on a single task (the 'do one thing well' principle). Small functions with a clear name, a well-defined return type, and few parameters are easier to test, debug, and reuse than one giant function that does everything.

4. Example

c
#include <stdio.h>

/* Function prototypes */
int square(int n);
int add(int a, int b);
void printLine(void);

int main(void) {
    int num = 6;
    int result = square(num);

    printf("Square of %d is %d\n", num, result);
    printf("Sum of 4 and 9 is %d\n", add(4, 9));
    printLine();

    return 0;
}

/* Function definitions */
int square(int n) {
    return n * n;
}

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

void printLine(void) {
    printf("------------------\n");
}

5. Output

text
Square of 6 is 36
Sum of 4 and 9 is 13
------------------

6. Key Takeaways

  • A function declaration (prototype) tells the compiler the name, return type, and parameter types; a definition provides the actual body.
  • Parameters are placeholders in the function signature; arguments are the real values passed during a call.
  • C uses pass-by-value only — functions receive copies of arguments, so changes inside the function do not affect the caller's originals.
  • To modify a caller's variable, pass a pointer to it and dereference the pointer inside the function.
  • The return statement sends a value back to the caller and must match the declared return type; void functions return nothing.
  • Always declare or define a function before it is called so the compiler can type-check the call.
  • C has no function overloading or default arguments (unlike C++) — each function name maps to exactly one signature.

Practice what you learned

Was this page helpful?

Topics covered

#CProgrammingStudyNotes#Programming#FunctionsInC#Functions#Syntax#Explanation#Declaration#StudyNotes#SkillVeris#ExamPrep

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse