C Language – External functions

  • 6
    Shares

C Language

 

The operations for many things, to enter the code: once we rewrite the identical pieces of code, why not use the same piece of code?

 

The functions are the same mathematics that insert values and functions returns a value, except in some cases.

 

In any case, I will declare the function, if you want it to return a character to declare an integer int, …….

 

You can declare it void but it will not return anything.

 

After having identified the type, put the name of the function and inside the round brackets.

 

Example:

 

int sum (int a, int b);

 

this will be a function that sums up two numbers.

 

The functions will be declared out of the principal, within the main code of the function.

 

Now it is a practical example where I will make simple numerical sums always the same code.

 

 

C Language

 

The first call to the function is result = sum (n, m)

 

Where “n” is associated with “a” and “m” a “b”, inside the function we then have “x” which is the result of a + b, at the end we return the x value to the main function and save it to the variable result.

 

The second call to the function is the result = sum (x, y) which does the same job as the first call, but where it passes different values.

 

I remind you that a good program inside the main uses only function calls, all the code must be written inside the external functions.

 

I recommend the name of the function will have to coincide with the work it does.

 

Stay Tuned! 


  • 6
    Shares

SviluppoMania - Piko

Salve, sono un ragazzo di 25 anni, iscritto alla facoltà di informatica, appassionato di programmazione e delle nuove news tecnologiche in ambito informatico.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

"GDPR" Data Request Form

Select your request: