C programming function

void0629
1 min readMay 27, 2021

A function is just like a black box, giving it inputs and manipulate inputs, return a single output eventually.

We need to declare a function before using it:

  • Prototype: type output name_function name_(type input name);
  • The underscore is just to ensure you can see it clearly, in the C program we use space instead.
  • this function prototype is simply just telling the compiler there’s a user-written compiler that appears in the code, so it should always on top of your code. (Outside the main functions)

Another step to make a function is function defining.

What you want it to do? state all the instructions clearly in the function scope following the programming language standard.

Below is a simple function that sums up the total value of the given input.

Example:

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

Summary

Declaring your own functions are really useful when your programs become larger and larger, you shouldn’t simply just leave all the code in your main function.

Benefits of declaring and defining functions outside of the main world

  • well structured, easy to organize.
  • reusability

--

--