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 int
s:
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
Post a Comment