Skip to content

Instantly share code, notes, and snippets.

@JuanCrg90
Created June 28, 2016 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanCrg90/5bcbf8050a0514688f2d9b4de8b6cd90 to your computer and use it in GitHub Desktop.
Save JuanCrg90/5bcbf8050a0514688f2d9b4de8b6cd90 to your computer and use it in GitHub Desktop.
Simple double pointer example in C-Lang
#include <stdio.h>
#include <stdlib.h>
int main () {
int **matrix;
int i;
int j;
int n;
int m;
scanf("%d", &n);
scanf("%d", &m);
matrix = (int**) malloc( sizeof(int*) * n );
for(i = 0; i < n ; i++) {
matrix[i] = (int*) malloc( sizeof(int) * m );
}
for(i = 0; i < n ; i++) {
for(j = 0; j < m; j++) {
matrix[i][j] = i * j;
}
}
for(i = 0; i < n ; i++) {
for(j = 0; j < m; j++) {
printf("%d ",matrix[i][j]);
}
printf("\n");
}
for(i = 0; i < n ; i++) {
free(matrix[i]);
}
free(matrix);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment