C program on the sum of two numbers using a function.

 program::

function in c

 output::


Explanation:

In the program, a function sum is declared with two parameters and one return type. In the main function, the sum function is called passing the arguments a and b and accepting a returned value under the "ans" variable.

Function declaration accepts the values passed by the function calling a and b under the declared variables x and y, x and y are local variables, and its existence is only under the body of function definition. Local variable z is declared under the body of function definition.

Sum of x and y is stored in z. the value under the z variable is passed to the main function by returning the value of z and storing it under the "ans" variable.

Hence, the value under the "ans" variable is printed, which is the sum of two numbers a and b.

 Also, see:

function in c 

call by value and call by reference