convert two dimensional array to one dimensional in C -


i have 2 dimensional array this:

ptr = (int **) malloc(size);  (i = 0; < len; i++) {     ptr[i] = (int *) malloc(size); } 

is there simple way create int *intptr array such can access values in row major order?

e.g.: if ptr points n*n array, want first item of second column this: *(intptr + n)

i need conversion pass 2 dimensional array cuda kernel, want avoid pass 2 dimensional array kernel because seems quiet complicated.

no. if had allocated true 2d array of ints:

int a[size][size]; 

then answer might yes though result not portable. refer this article more array type punning information.

but accessing element in row of array requires explicitly dereferencing pointer.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -