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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started