first of all I looked other titles about segmentation faut 11 error.
This one is very close to me. But cannot solve my problem. How to fix segmentation fault 11 error
This code take 2 array from user with readArray
function
Here is the code
int *readArray(int p[]) {
int i = 0;
printf("Enter the array :\n");
for (i = 0; i <= 10; i++) {
printf("a%d : ", i);
scanf("%d", &p[i]);
}
return p;
}
int main() {
int *firstArray;
int *secondArray;
int *resultArray;
firstArray = readArray(firstArray);
// printArray(firstArray);
secondArray = readArray(secondArray);
// printArray(secondArray);
// addArray(firstArray,secondArray,resultArray);
// printArray(resultArray);
printf("\n");
return 0;
}
I can take first one from user but cannot take second. It gets error segmentation fault 11.
How can I solve it?
Thank you all! FIXED CODE
void readArray(int p[]) {
int i = 0;
printf("Enter the array :\n");
for (i = 0; i < 11; i++) {
printf("a%d : ", i);
scanf("%d", &p[i]);
}
}
int main() {
int firstArray[11];
int secondArray[11];
int resultArray[11];
readArray(firstArray);
// printArray(firstArray);
readArray(secondArray);
// printArray(secondArray);
// addArray(firstArray,secondArray,resultArray);
// printArray(resultArray);
printf("\n");
return 0;
}