c++ - How do i dynamically allocate memory to a 2D array in C avoiding the stack overflow issue? -


pascal = (int **) malloc(no_of_rows * sizeof(int));  (i = 0; < no_of_rows; i++) {     *(pascal + i) = (int*) malloc(col * sizeof(int)); } 

can tell me what's wrong in code beginner language. keep on getting problem of stack overflow? possible reasons , how avoided?

pascal=(int **)malloc(no_of_rows * sizeof(int)); 

should be

pascal=malloc(no_of_rows * sizeof(int*)); 

notice additional * added. in general, can write better:

pascal=malloc(no_of_rows * sizeof *pascal); 

note casting mallocs results unnecessary in c.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -