I need to write a program that implements 3 ways of passing an array to a function.
2 functions work as intented, but I am having issues with the function that passes a pointer. I tried googling it, and testing other way, but I don't seem to understand how those pointers should work out. First function should output 1, 2, 3.
Second function should output 11, 12, 13
Third function should output 101, 102, 103
First and third function work, but the issues is with the second one. Here's what I wrote:
int main(void)
{
int iArray[3] = {100,234,567};
f1(iArray);
f2(iArray);
f3(iArray);
return EXIT_SUCCESS;
}
void f1(int ia[3]) // sized array
{
ia[0] = 1;
ia[1] = 2;
ia[2] = 3;
for (int i = 0; i < 3; i++)
{
printf("%d\n", ia[i]);
}
printf("\n");
}
void f2(int* pi) // pointer
{
*pi = 11, 12, 13;
printf("%d", *pi);
printf("\n\n");
}
void f3(int ia[]) // unsized array
{
ia[0] = 101;
ia[1] = 102;
ia[2] = 103;
for (int i = 0; i < 3; i++)
{
printf("%d\n", ia[i]);
}
}
int*argument). Welcome to C :)*pi = 11, 12, 13;==>*pi = 11; *(pi + 1) = 12; *(pi + 2) = 13;