#include<conio.h>
#include<stdio.h>
void fun(int []);
int main(){
int arr[10] = {1,1,1,1,1};
int i=0;
printf("Before Change : ");
for( i=0;i<5;i++){
printf("%d, ",arr[i]);
}
fun(arr);
printf("\nAfter Change : ");
for( i=0;i<5;i++){
printf("%d, ",arr[i]);
}
getch();
}
void fun(int a[])
{
int i;
for(i=0;i<5;i++){
//a[i] = a[i]++; // Comment 1
//a[i] = ++a[i]; // Comment 2
}
}
When I use Comment 1 Statement then I Get this output:
Before Change : 1, 1, 1, 1, 1,
After Change : 1, 1, 1, 1, 1,
When I use Comment 2 Statement then I Get this output:
Before Change : 1, 1, 1, 1, 1,
After Change : 2, 2, 2, 2, 2,
Here I know that why Comment 2 Statement get array Change Due to pre increment. But my question is Why Comment 1 Statement not able to Change array elements, since changes made in other function (here is fun()) is able to effect same changes in same array.
So Why array elements do not change in comment 1 statement?