What am I missing? If I want to increment a counter in a separate function, why does it give me a segmentation fault?
int point(int *cow);
int main()
{
int *cow = 0;
point(cow);
return(0);
}
int point(int *cow) {
(*cow)++;
return(0);
}
Dereferencing a null pointer is undefined behavior in C.
Maybe you wanted to do this instead:
Note that the temporary pointer
cowis not necessary and you can directly pass&atopointfunction.