I’m writing a C program. It compiles fine but when I try to run the binary I get a seg fault. I ran gdb but I got a problem at the following line
*total = a;
The problem is right at the beginning of the code. Here it is:
main(){
int a[] = {1,1,1,0,0,0,0};
int **total; //array of int arrays
*total = a; //i.e. set total's first array to be a.
I’m new to C and pointers. Any help would be appreciated.
totalpoints to a pointerpwhich points to an int. By assigning to*total, you’re assigning top. Buttotalhasn’t been initialized, so you’re assigning a value into a random location. You need to initializetotal— for example