Programming Example
Write C a program that uses a function show call by value mechanism.
Write C a program that uses a function show call by value mechanism.
#include <stdio.h>
int mul_by_10(int num); /* function prototype */
int main(void)
{
int result,num = 3;
printf("\n num = %d before function call.", num);
result = mul_by_10(num);
printf("\n result = %d after return from function", result);
printf("\n num = %d", num);
return 0;
}
/* function defi nition follows */
int mul_by_10(int num)
{
num *= 10;
return num;
}
num = 3 before function call.
result = 30 after return from function
num = 3
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.