Question: Consider the following piece of C code: #include #include int x; int bar(int a, int b) { int i = b; b = i +
Consider the following piece of C code:
#include
#include
int x;
int bar(int a, int b)
{
int i = b;
b = i + 10;
return x + b;
}
void foo(int a, int* b)
{
int c[3] = {0,0,0};
int d;
b = malloc(sizeof(int));
*b = 42;
d = bar(a, c[++x]);
a = 101;
printf("%d ", a);
printf("%d ", *b);
printf("%d ", c[0]);
printf("%d ", c[1]);
printf("%d ", c[2]);
printf("%d ", d);
}
int main()
{
x = 0;
int* y = malloc(sizeof(int));
*y = 20;
foo(x, y);
printf("%d ", x);
printf("%d ", *y);
return x;
}
a. What is the output of this program if parameters are passed by value?
b. What is the output of this program if parameters are passed by reference?
c. What is the output of this program if parameters are passed by name?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
