Search
 
SCRIPT & CODE EXAMPLE
 

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);
}
Comment

2d array in c

#include <stdio.h>
int main(){
    int scores[3][3],i,j;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("a[%d][%d] = ",i,j);
            scanf("%d",&scores[i][j]);
        }
    }

printf("
 Matrix view: 
");
for (i=0;i<3;i++)
{
    for (j=0;j<3;j++){
        printf("%d	",scores[i][j]);
    }
    printf("
");
}
}
Comment

2D Array In C

// Array of size n * m, where n may not equal m
for(j = 0; j < n; j++)
{
    for(i = 0; i < m; i++)
    {  
        array[i][j] = 0;
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: factorial c program using for loop 
C :: golang loop through array 
C :: read files in c 
C :: c get file size 
C :: space after format specifiers in c 
C :: how to map one value to another in C 
C :: scanf ignore new line 
C :: if statement shorthand c 
C :: how to search in a file in c 
C :: printf fill with 0 
C :: malloc int array c 
C :: successeur d’un entier donné 
C :: input in c 
C :: scan numbers into array c 
C :: c bit access union 
C :: printf type format 
C :: ROUNDING decimal number in C 
C :: check if string in string c 
C :: downgrade chrome to previous stable version in linux 
C :: slug urls django 
C :: how to read keyboard input in C 
C :: prime number c program 
C :: measure time in c 
C :: mount cifs 
C :: how to make a check bigger 
C :: how compress string in c 
C :: c program for swapping of two numbers 
C :: iterate through enum in qt 
C :: arduino empty serial buffer 
C :: time include c 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =