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 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;
}
 
                        

🖥 Program Output

Elements are 10, 2, and 20.

 
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.