Skip to content
thesarfo

Note

C: Functions

Defining and calling functions in C, and what the return type declaration means.

views 0
#include <stdio.h>
int plus_one(int n) { /* defining the function */
return n + 1;
}
int main(void){
int i = 10, j;
j = plus_one(i); /* calling the function */
printf("i + 1 is %d\n", j);
return 0;
}

Adding int before a function simply states that the function returns a datatype of integer; void means it returns nothing.

Define a function before calling/using it, else the compiler won’t know what it is when it runs the main function.