Answer:
Check the explanation
Step-by-step explanation:
By doing call by value parameter passing the values remain unchanged even after the function call as the values of actual parameters cannot be altered with the help of the formal parameters. Here is an example code of the above stated C syntax and it’s output clearly shows that there is no change in the values even after function incr is called.
Code in C:-
#include <stdio.h>
// function incrementing the values
void incr(int first, int second)
{ printf("\\Before updation in the values\\first = %d second = %d",first,second);
// incrementing the first and second values
first = first + 1;
second = second+ 1;
printf("\\After updation in the values\\first = %d second = %d",first,second);
}
int main()
{ // Decalring the values of a and b
int a=3, b=5;
printf("\tCALL BY VALUE\\\\");
printf("Before the function call\\a = %d b = %d",a,b);
// Value passing in the function incr
incr(a,b);
printf("\\After the function call\\a = %d b = %d",a,b);
return 0;
}
Kindly check the first and second attached image below for the code screenshot and code output.
By doing call by reference parameter passing the values change after the function call as the values of actual parameters can be altered with the help of the formal parameters. Values are passed as a reference in this case. Here is an example code of the above stated C syntax and it’s output clearly shows that there is change in the values after function incr is called.
Code in C:-
#include <stdio.h>
// function incrementing the values
void incr(int *first, int *second)
{ printf("\\Before updation in the values\\first = %d second = %d",*first,*second);
// incrementing the first and second values
(*first)=(*first)+ 1;
(*second)=(*second)+ 1;
printf("\\After updation in the values\\first = %d second = %d",*first,*second);
}
int main()
{ // Decalring the values of a and b
int a=3, b=5;
printf("\tCALL BY REFERENCE\\\\");
printf("Before the function call\\a = %d b = %d",a,b);
// Reference passing in the function incr
incr(&a,&b);
printf("\\After the function call\\a = %d b = %d",a,b);
return 0;
}
Kindly check the third and fourth attached image below for the code screenshot and code output.