The following program accidentally writes Parr as a *parr in 11 rows scanf (), which is not a problem at compile time, but appears at run time:
[Lujinhong@lujinhong chapter12]$ gcc reverse3.c
[Lujinhong@lujinhong chapter12]$./a.out
Enter number:19 76 8 93 766 8 6 934 0-3
Segmentation fault (core dumped)
#include <stdio.h>
#define ARRAY_SIZE
int main (void) {
int arr[array_size], *parr;
printf ("Enter%d number :", array_size);
for (Parr=arr; parr<arr+array_size; parr++) {
scanf ("%d", *parr);
}
printf ("The number would output in reversal order:\n");
for (parr=arr+array_size-1; parr>=arr; parr--) {
printf ("%d\t", *parr);
}
printf ("\ n");
return 0;
Segmentation fault (core dumped) is generally caused by improper memory operation, and it is common to:
(1) The array is out of range.
(2) Read-only memory has been modified.
(3) This example also modifies the read-only memory.