Local Variables

Learn how local variables work in functions.

Local variables project

Let’s learn more about local variables with a project.

Source code

The source code of the local variables project is given below:

Press + to interact
int main()
{
int a, b;
a = 1;
b = 1;
b = b + a;
++a;
b = b * a;
return 0;
}

Compilation and execution of code

We compile the file and load the executable into GDB:

gcc LocalVariables.cpp -o LocalVariables
gdb ./LocalVariables

The output after loading the executable file:

Then we put a breakpoint to the main:

break main

The breakpoint ...