krm krm - 1 year ago 78
C Question

How to treat possible NULL pointers in a 2d dynamic array in a C program?

When allocating memory for a 2d dynamic array in C, can you treat the inner array (columns) with a function like the following example? Also, how can you print the NULL pointer message with the number of the NULL column pointer?

int main()


int ** x = calloc(N, sizeof(*x));

for(int i=0; i<N; i++){




void error(int *x){


Answer Source

Change your function to

void error(int *x, int idx)

and call

error(x, i);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download