Just when you thought you'd learn a new language without paying much attention to a "Hello World!!!" here it goes.
This video highlights the main steps of writing a simple function without parameters nor return value in a single-file project.
Video Duration - 03"48 / Development Environment - Windows / JGrasp / MinGW
The term "stack" is used here as short for "program's execution stack" and is not to be confused with the data structure
which has been introduced to you when you studied lists.
The idea of a stack diagram is to help us understand what happens in the memory area of our program holding local variables
and the information necessary to handle each separate invokation of each function. This understanding is fundamental to write
and troubleshoot just about any program involving functions of your own or functions from the standard library.
As we learn more about pointers, such diagrams will be necessary to help the novice programmer figure out what a given program
is doing, or what their own programs ought to be doing.
For this reason, stack diagrams are often used while "tracing" a program step by step on paper as is illustrated in this video.
Be sure to use this technique often as we pile more and more difficult techniques in our programs.
So far, any parameter of the elementary data types has been "unmodifiable" inside functions.
Even if you modify it by assigning a different value, the effective parameters remain the same.
Our language is said to pass parameters by value only, which explains what is happening when we fail
at writing the simple function meant to swap the values in two parameter variables, as explained in this video.
Suggestion - Try writing a similar method in Java. What is going on?
Video Duration - 05"17 / Development Environment - Windows / JGrasp / MinGW
This video illustrates the solution to our swap function but, in order to get it to work, introduces the idea of
pointer and the associated syntax based on the * and & operators.
Video Duration - 06"38 / Development Environment - Windows / JGrasp / MinGW
Now that we know why the original swap didn't work and were able to implement a working solution, let us apply our
stack diagram based tracing skills to thoroughly understand what's going on under the hood.