Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

dynamic 2d arr in c

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int i, j, col = 3, row = 4;

	/* create dynamic 2d arr (matrix) */
  
    int **m = (int**)malloc(col * sizeof(int)); 
    for(int i = 0; i < col ; i++){
        m[i] = (int*)malloc(row * sizeof(int));
    }
  	
  	/* after usage free it */
  
    for (int i = 0; i < row; i++){
        free(m[i]);
    }
    free(m);
}
 
PREVIOUS NEXT
Tagged: #dynamic #arr
ADD COMMENT
Topic
Name
6+7 =