Functions in C for Unit III: User-Defined Functions, Inter-Function Communication, Storage Classes, and Scope Rules

The syllabus for this unit covers functions, inter-function communication, storage classes, and scope rules — and this blog already has a complete, detailed 3-part series covering exactly this ground in depth. Rather than repeat that material, this post is a short guide mapping each syllabus topic to the right part of that series, plus a couple of points specific to how these ideas are typically framed in exams. This is Post 3 of the Unit III series — Post 2 covered sorting algorithms.

Where to find each topic: User-defined functions & basics: Functions in C Part 1. Inter-function communication (parameter passing) & scope rules: Functions in C Part 2. Storage classes: Functions in C Part 3.

What “Inter-Function Communication” Actually Means

This syllabus term refers to how data moves between functions — a function receiving input (its parameters) and sending output (its return value), plus how a function can affect a caller’s variables through pointers. Concretely, this covers:

  • Call by value — the default; the function works on a copy, the caller’s original is untouched.
  • Call by reference — passing addresses (&) so a function can modify the caller’s actual variables via pointers (*).
  • Return values — a function sending a single result back via return.

All three are covered with full worked examples (including the classic swap() function and a minMax() function that returns two results via pointers) in Part 2 of the Functions series.

Scope Rules: Quick Recap

“Scope rules” asks where a variable is visible and how long it lives:

  • Local scope — variables declared inside a function; visible and alive only during that function’s execution.
  • Global scope — variables declared outside all functions; visible to every function in the file, alive for the whole program.
  • Block scope — a variable declared inside { } (like inside an if or loop body) is only visible within that block.
#include <stdio.h>

int globalCount = 0;   // global scope

void demo() {
    int localVar = 10;   // local scope — exists only during demo()

    if (localVar > 5) {
        int blockVar = 99;   // block scope — only visible inside this if-block
        printf("blockVar = %d\n", blockVar);
    }
    // blockVar is NOT accessible here — it's out of scope

    globalCount++;
}

int main() {
    demo();
    demo();
    printf("globalCount after two calls: %d\n", globalCount);
    return 0;
}

Sample Output

blockVar = 99
blockVar = 99
globalCount after two calls: 2

Storage Classes: Quick Recap

Storage classes (auto, static, extern, register) control a variable’s lifetime and linkage, layered on top of ordinary scope. The most exam-relevant one is static, since it directly changes a local variable’s expected behavior (retaining its value between calls, instead of resetting) — see the countCalls() example in Part 3 for a full walkthrough.

An exam-style trap question to watch for: “What does this function print if called three times in a row?” questions almost always hinge on whether a local variable is static or not. If it’s an ordinary (auto) local variable, it resets every call; if it’s static, it remembers its value. Always check for the static keyword before assuming a local variable starts fresh on each call.

Summary

  • Full explanations, examples, and diagrams for user-defined functions, parameter passing, scope, storage classes, and function pointers are already covered in the 3-part Functions series — this post exists as a syllabus-aligned index into that series.
  • “Inter-function communication” = call by value + call by reference + return values.
  • Scope rules = local vs. global vs. block visibility.
  • Storage classes = auto/static/extern/register, layered on top of scope to control lifetime and cross-file visibility.

Further Reading

Next in this series: recursive functions, revisited with recursion-tree diagrams — closing out Unit III.

Leave a Comment