Question: #include int x = 30; int y = 40; int z = 50; void func() { x = x+1; y = y+2; z = z+
#include
int x = 30;
int y = 40;
int z = 50;
void func()
{ x = x+1;
y = y+2;
z = z+ 3;
printf("func is x=%d, y=%d z=%d , x, y,z");
}
void func2()
{ int z = 20;
y = y+2;
z = z+ 3;
func();
printf("func2 is x=%d, y=%d z=%d , x, y,z");
}
int main(int main(int argc, char *argv[])
{
func2();
printf("main is x=%d, y=%d z=%d , x, y,z");
}
The question is if I move the global variables x, y, z to main(), how do I pass x and y to func2() from main and pass addresses of x, y, z from func2() to func(). I want to mimic a dynamic scope in C.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
