In: Computer Science
Create a memory diagram for the following C program when the program reaches point 1.
void foo (int *a);
int bar(int *x);
int search(int *c);
int main(void)
{
int q, p=10;
q= search(&p);
return 0;
}
void foo(int *a)
{
*a += 2;
//point 1
*f *= 10;
}
int bar(int *x)
{
return 2* *x;
}
int search(int *c)
{
int z= *c + bar(c);
foo(c);
return z;
}
For given c program:
void foo (int *a);
int bar(int *x);
int search(int *c);
int main(void)
{
int q, p=10;
q= search(&p);
return 0;
}
void foo(int *a)
{
*a += 2;
//point 1
*f *= 10;
}
int bar(int *x)
{
return 2* *x;
}
int search(int *c)
{
int z= *c + bar(c);
foo(c);
return z;
}
Summary: Starting execution from main function, two variables p type integer equals 10 and address of p passed as parameter calling search function, from search bar with address of p passed bar computes 2 * 10 and returns 20 and bar discarded from stack, z value computed as 30 in search, after foo is called where *a becomes 12.