Call by value - Parameter Passing Methods - C Programming
Find the cube of given value.
/* C Program to find the cube of given value */
#include <stdio.h>
int cube (int x)
main()
{
/* Local definition */
int n=5;
/* Statements */
printf("Cube of %d is..%d", n,cube(n));
} /* main */
int cube(int); /* cube is a function to cubic the values */
{
x=x*x*x;
return(x);
} /* cube */
OUTPUT
Cube of 5 is.. 125
EXPLANATION: In this example, the value of argument to the function cube(), is copied to the parameter 'x'. The expression x= x*x*x is evaluated, and only the local variable 'x' is modified. The main program print the value of n and transfers the control to called function cube() and calling program get back the values from the called program cube(). The function cube() executes the block of statement and return the values to the main function.
Computer Programming C Laboratory: Functions C Programs : Tag: C Programming : - C Program to find the cube of given value (Call by value)