c - How to allocate memory to int (*a)[2]? -


how allocate memory integer type (*a)[2] ? comfortable doing **a, *a etc. etc., *a[2], looks different.

can out ? in advance.

same pointer type, have

int (*a)[2]; 

a pointer a arrays of 2 int, allocate

a = malloc(number_of_rows * sizeof *a); 

to block of number_of_rows * (2 * sizeof (int)) bytes.

you access with

a[i][j] 

with 0 <= < number_of_rows , 0 <= j < 2.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -