what is wrong with my program?
Hi all. I’m writing this program in which I use a function that returns “int *”. Actually I wanted an array to be returned and since it’s not possible, I return array s at the end of the function( s here is treated as the pointer to the first element of the array. Isn’t it?)
Later in my program I use this function in the following for loop:
int* function1(int a,int c, int b)
function1, which was defined before, returns a pointer to the first element of the array. Then it is added with “y” so that it moves to the next memory space and points to the following elements of array s. in each iteration of the loop the pointer points to a specific element of s and by using the operator * and assigning *(pointer) to array s1, I expected the elements of array s1 to get the values of the previously defined array s.
for(int y=0 ; y<1000; y++)
But when I debugged my program and I observed the changes in the variables and stuff, I noticed that the elements of array s1 all have the same nonsense value of -858993460.
I have tested function1 separately and there’s nothing wrong with it.
Can someone please tell me what is wrong with my program?