Functions are self-contained blocks of code that can be called upon by other parts of the program. They make it very easy to repeat code, and they help make the program simpler to read and change. Functions can include all of the previously-covered techniques learned in this article, and even other functions.       The main() line at the beginning of all of the above examples is a function, as is getchar()  Functions are essential to efficient and easy-to-read code. Make good use of functions to streamline your program. Functions are best created when you outline what you want it to accomplish before you begin the actual coding. The basic syntax for functions is "return_type name ( argument1, argument2, etc.);". For example, to create a function that adds two numbers:   int add ( int x, int y );    This will create a function that adds two integers (x and y) and then returns the sum as an integer. You can use the outline to create a program that takes two integers that the user enters and then adds them together. The program will define how the "add" function works and use it to manipulate the input numbers.   #include <stdio.h>  int add ( int x, int y );  int main() {   int x;   int y;    printf( "Enter two numbers to add together: " );   scanf( "%d", &x );   scanf( "%d", &y );   printf( "The sum of your numbers is %d\n" , add( x, y ) );   getchar(); }  int add ( int x , int y ) {   return x + y; }    Note that the outline is still located at the top of the program. This tells the compiler what to expect when the function is called and what it will return. This is only necessary if you want to define the function later in the program. You could define add() before the main() function and the result would be the same without the outline. The actual functionality of the function is defined at the bottom of the program. The main() function collects the integers from the user and then sends them to the add() function to be processed. The add() function then returns the results to main()  Now the add() has been defined, it can be called anywhere in the program.
أساسيات الدوال. البدء بوضع الإطار الرئيسي للدالة. إضافة الدالة إلى البرنامج.