Search
 
SCRIPT & CODE EXAMPLE
 

C

Dynamic Memoray alocation For 2D

#include <stdio.h>
#include <stdlib.h> 
int main() {
   int row = 2, col = 3;
   int *arr = (int *)malloc(row * col * sizeof(int)); 
   int i, j;
   for (i = 0; i < row; i++)
      for (j = 0; j < col; j++)
         *(arr + i*col + j) = i + j;    
   printf("The matrix elements are:
");
   for (i = 0; i < row; i++) {
      for (j = 0; j < col; j++) {
         printf("%d ", *(arr + i*col + j)); 
      }
      printf("
");
   }
   free(arr); 
   return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: c program to take array input from user 
C :: condition ternaire in c 
C :: Integer Xor swap 
C :: djb2 algorithm for C 
C :: visa germany algeria 
C :: gnunet 
C :: diiferent between * and & in c 
C :: assembly to c code converter 
C :: counting 7s in an integer c 
C :: arcpy buffer 
C :: get file ligne count c 
C :: copy a number of characters to another string in c without standard library 
C :: nc,manc 
C :: captive portal esp8266 
C :: float and double Output 
C :: C Relationship Between Arrays and Pointers 
C :: passing an array of unspecified number of variables to a function 
C :: c programming trinary if 
C :: calculate max of three numbers using ternary operator in c 
C :: time random c 
C :: default password raspberry pi 
Dart :: flutter get millis time 
Dart :: flutter padding top and bottom 
Dart :: italic text flutter 
Dart :: rotate IconButton flutter 
Dart :: raisedbutton shape flutter 
Dart :: not empty string check dart 
Dart :: flutter text decoration underline color 
Dart :: dart integer division 
Dart :: card border radius flutter 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =