Any time your program gives a "segmentation violation" or "segmentation fault" error, review this document for tips on correcting the error.
int * ptr;
int variable;
ptr = &variable;
Or, equivalently,
int variable;
int *ptr = &variable;
Other common ways include assigning the pointer the address of memory allocated with matrix, vector, calloc, or malloc or other equivalent allocation functions. Remember, a pointer must be initialized to a value (i.e., assigned a value by appearing on the left-hand-side of an assignment statement) BEFORE you attempt to access it!
double x_initial; /* initial guess */
scanf("%lf",&x_initial); /* Read the initial guess. */
For example, see how 'idum' is used below:
long idum = -1; /* initialize idum to be a negative integer */
/* generate a random number from the normal distn.*/
x = normal(&idum,average,stddev);
The function normal expects an address to a variable of type long. That's what we send it without explicitly using a pointer variable in the calling routine.
If the program uses many pointers and has many occurrences of & and *, then add some printf statements to pinpoint the place at which the program causes the error and investigate the pointers and variables involved in that statement.
Remember that printf statements for debugging purposes should have a new-line character (\n) at the end of their format control strings to force flushing of the print buffer.