Home / Programs / Write C a program to show that when arrays or strings are passed to a function, call by value mechanism is not followed.
Programming Example

Write C a program to show that when arrays or strings are passed to a function, call by value mechanism is not followed.

👁 815 Views
💻 Practical Program
📘 Step by Step Learning
Write C a program to show that when arrays or strings are passed to a function, call by value mechanism is not followed.

Program Code

#include<stdio.h>
void change(int []);
int main(void)
{
	int arr[3] = {1, 2, 3};
	change(arr);
	printf("Elements are %d, %d, and %d.\n", arr[0], arr[1], arr[2]);
	return 0;
}
void change(int my_array[])
{
	my_array[0] = 10;
	my_array[2] = 20;
	return;
}
 

Output

Elements are 10, 2, and 20.

 

Explanation

None

How to learn from this program

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.