Functions in programming work a lot like they do in math, except programming functions get better names that f() or g().
In math, when you say f(x) = 2x, you are defining a rule: for input x, output 2 times x. In programming you have the same idea, except it can be more complicated. Because we have various data types (float, int, etc) you need to be precise about the input and output when you define your function. Also, they can do a lot more complicated stuff.
Code:
float f(float x)
{
float temp;
temp = 2*x;
return temp;
}
This programming function f does the same as the math function.
-----
If we look at g(x) = 2 sqrt(x), things get more complicated.
Code:
float g(float x)
{
float temp;
temp = 2*sqrt(x);
return temp;
}
float sqrt(float x)
{
// do something
}
Notice how x gets passed into g, which has to hand it off to sqrt. This chain can happen for multiple levels, one function calling another calling another. If, at any point, one of them says "I'm not allowed to change x", then any changes that functions it calls try to make will be cancelled out when it refuses to pass those changes back.