Answers for "dynamic int matrix c"

C
1

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);
}
Posted by: Guest on January-21-2022
1

dynamically create matrix c

int **A = (int **)malloc(N * sizeof(int*));

for(i=0; i<N; i++){
    A[i] = (int *)malloc(N * sizeof(int));
}
Posted by: Guest on April-29-2021

Code answers related to "C"

Browse Popular Code Answers by Language