The question I'm tackling:
Write a program that
(1) defines a 1D array with ten int elements, and
(2) sets the values of the elements such that they are equal to the addresses of the elements, and
(3) prints out the content of the elements.
The program should call a user-defined function value_address with the following function prototype: void value_address( int[] )
My answer:
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- int main(void)
- {
- int array[10], i;
- void value_address(int[]);
- value_address(array);
- for (i=0;i<10;i++)
- printf("Value of array[%1d] is %d\n", i, array[i]);
- return 0;
- }
- /* function definition for value_address */
- void value_address(int inarray[])
- {
- int i;
- for (i=0;i<10;i++)
- inarray[i] = &inarray[i];
- }
I'm getting an error message Invalid conversion from 'int*' to 'int' on the line below
inarray[i] = &inarray[i];
What am I doing wrong?
Thanks :)