Skip to content
Justice Tech School

Functions

A function has a return type, a name and parameters. Declare it before use (a prototype) or define it above main. void means no return value. Arguments are passed by value, so the function works on copies.

Example
#include <stdio.h>

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

void greet(const char *name) {
  printf("Hello, %s\n", name);
}

int main(void) {
  greet("Ada");
  printf("%d\n", add(2, 3));
  return 0;
}

Result

Hello, Ada
5

Exercise

A function with no result returns...

 greet(void) {}

Quiz Test

How are arguments passed by default?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.