I'm coming from a dominantly object-oriented programming language and trying to understand the functioning of C a little more so decided to make a small program to do this.
The problem I am having is what is usually addressed with the use of DI, how do I pass the reference of a value to another function so that it can perform arithmetic on it without using globals?
Consider the following program:
#include <stdio.h>
#include <stdlib.h>
int doStuff(int v)
{
v = v + 10; // main->value = 10
}
int otherStuff(int v)
{
v = v - 10; // main->value = 0
}
int main()
{
int value = 0;
int stop = 0;
do
{
printf(" %i should be 0 \n", value);
doStuff(value); // "value" = 10
printf(" %i should be 10 \n", value);
otherStuff(value); // "value" = 0
printf(" %i should be 0 \n", value);
exit(0);
if(value >= 10)
{
stop = 1;
}
} while(!stop);
}
Output:
0 should be 0
0 should be 10
0 should be 0