I'm very new to programming so please bear with me!
This is my code (in C):
int * arrayExpander(int arr[], int size);
int main()
{
int arr[] = { 1,2,3,4,5 };
int size = 5;
int* arrPtr = arrayExpander(arr, size);
for (int i = 0; i < size * 2; i++) {
printf("New array: %d \n", *arrPtr);
}
}
int * arrayExpander(int arr[], int size)
{
int newInt[10];
int* expandedArr = &newInt;
//move elements from original to expanded and initialise remaining elements with 0
for (int i = 0; i < size * 2; i++) {
if (i < size) {
expandedArr[i] = arr[i];
} else {
expandedArr[i] = 0;
}
}
return expandedArr;
}
My print statement isn't printing the values stored in the expandedArr correctly. I've tried a few variations and not sure how to fix it.
Thanks in advance