Skip to content
Learn Netverks

Lesson

Step 10/36 28% through track

functions

Functions

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Functions: the syntax, patterns, and safety habits you need before advancing in C.

Teams still ship Functions in C codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Functions in contexts like: Kernels, drivers, embedded devices, and performance libraries used by other languages.

Write C in main.c with int main(), click Run on server—the dev runner compiles with cc/gcc -std=c11 and runs the binary; read stderr for compile and linker errors (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Functions group reusable logic. Declare return type, name, parameters, and body. Unlike Java methods, C has no classes—functions are file-scope or static for internal linkage.

Definition example

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

Parameters are passed by value—copies are made. To modify caller data, pass pointers (covered soon).

Prototypes

Callers should see a prototype before use: int add(int a, int b); at file top or in a header.

Important interview questions and answers

  1. Q: Pass by value vs reference?
    A: C always passes by value; "pass by reference" means passing a pointer to the original object.
  2. Q: void parameter list?
    A: void f(void) takes no arguments; empty parentheses in old C mean unspecified parameters—avoid.

Self-check

  1. How do you return an int from a function?
  2. Why pass a pointer instead of a large struct by value?

Interview prep

Pass by value in C?

Arguments are copied; to mutate caller data, pass a pointer to the original object.

Why prototypes?

Compiler checks argument types and return type at call sites—missing prototypes cause errors or undefined behavior with old-style assumptions.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Pass by value?
  • Prototype why?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump