Created
June 28, 2016 01:24
-
-
Save JuanCrg90/5bcbf8050a0514688f2d9b4de8b6cd90 to your computer and use it in GitHub Desktop.
Simple double pointer example in C-Lang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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