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

C Programming Language Function in C Language (Article) Function in C Language (Program)

731

Program:

#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

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.