You are on page 1of 16

Variables & functions

Programming fundamentals - part 01/04


1.
WHat is a variable ?
Value Variable

A variable is like a “box”, it has a “name” and


you can put a “value” inside.
2.
How does it work ?
What’s “really” happen in the following code:
what’s “value” will be displayed and why ?
First, the 7 “value” is
put inside the X “variable”
Next, the 7 “value” is
copied from the X “variable” to the Y “variable”
Next, the 8 “value” is
put inside the X “variable”
So, the 7 “value” is
of the Y “variable” is displayed.
3.
WHat is a FUNCTION ?
In programming, a function is a named section of a program that
performs a specific task.
In other words, it’s a “black box” doing things when we call.
Sometimes, it can take “parameters” as Input and maybe it
“returns” something as Output.
So what’s “really” happen in the following code ?
As previously, “values” are copied
from the X and Y “variables” into
the “Inputs” and the “Output
value” is copied into the TOTAL
“variable”.
Let’s go deep into this “function”...
First, other “variables” named arg1 and arg2
receive the incoming “values” 2 and 3.
Next, a third “variable” named res receives the
resulting “value” of the (2 + 3) expression, so 5.
In the end, the 5 “value” is returned as “Output”
of the function.

You might also like