Skip to main content

passing array to a function by declaring pointers in the function

#include <stdio.h>
int fun1(int* ptr)
{
for (int i = 0; i < 4; ++i) {
printf("The value of %d is %d\n",i,ptr[i]); //or
printf("The value of %d is %d\n",i,*(ptr+i)); // both do the same work
}
*(ptr+2)=58; //value gets changed of 2nd index of array
}
int main ()
{
int arr[]={2,4,6,8};
fun1(arr);
fun1(arr);
return 0;
}

Comments