thank you in advance #include #include int x; int bar(int a, int b) int i-b; ret
ID: 3920533 • Letter: T
Question
thank you in advance
#include #include int x; int bar(int a, int b) int i-b; return x + b; void foo(int a, int* b) int c[3]- e,0,ej; int d; bmalloc(sizeof(int)); *b = 42; d = bar(a, a101; c[++x)); printf("%d ", printf("%d ", printf("%d ", printf("%d ", printf("%d ", printf("%d ", a); *b); c[0]); c[1]); c[2]); d); int main() int* y -malloc(sizeof(int)); *y -20; foo(x, y); printf("%d ", x); printf("%d ", *y); return x; What is the output of this program if parameters are passed by value? What is the output of this program if parameters are passed by reference? What is the output of this program if parameters are passed by name?Explanation / Answer
Hi.. I have tested below program for the 3 types.
#include <stdio.h>
#include <stdlib.h>
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;
}
Output:
pass by value
101
42
0
0
0
11
1
20
Pass by reference
101
42
0
0
0
11
1
20
Pass by name:
101
42
0
0
0
11
1
20
It results same for all the three types.
Please check and let me know any issues. Thank you. All the best.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.