So I have a pointer and a size of the array that gets passed down to a function that asks for user input and stores user input as array elements.
So the function looks like this:
int addElements(int * ptr, int sizeArr) {
int k=0;
for (k=0; k<=size; k++) {
printf("please enter element number %d\n", k);
scanf("%d", *(ptr+k));
}
return pArr;
}
It returns a pointer because I need to work further with the array.
I get
Segmentation fault (Core dumped)
error when inputting the elements to the array.
What am I doing wrong here? I can update the array elements (from random/automatic values ) to 0 just fine it's just the scanf that can't write to the array.