This is a C Program to illustrate pass by reference.
This program illustrates pass by reference.
1. Pass the addresses of the variables as parameters to the function.
2. In function definition receive the parameters through pointers.
3. Print the output and exit.
Here is source code of the C Program to illustrate pass by reference. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Illustrate Pass by Reference
void cube( int *x);
int num = 10;
printf("the cube of the given number is %d", num);
void cube(int *x)
*x = (*x) * (*x) * (*x);
1. Initialize the variable num to 10.
2. Call the function cube and pass the address of variable num as parameter.
3. In the function definition, receive the parameter through pointer x and compute the cube of the variable through pointer x.
4. Print the variable num as output in the main function and exit.
output: the cube of the given number is 1000
Sanfoundry Global Education & Learning Series – 1000 C Programs.