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
Post a Comment