c - How can I allocate a 2D array using double pointers? -


i want know how can form 2d array using double pointers?

suppose array declaration is:

char array[100][100]; 

how can double pointer has same allocation , properties?

typical procedure dynamically allocating 2d array using pointer-to-pointer::

#include <stdlib.h> ... t **arr; // type t arr = malloc(sizeof *arr * rows); if (arr) {   size_t i;   (i = 0; < rows; i++)   {     arr[i] = malloc(sizeof *arr[i] * cols);     if (arr[i])       // initialize arr[i]     else       // panic   } } 

note since you're allocating each row separately, contents of array may not contiguous.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -