Created
July 12, 2015 12:06
-
-
Save lesovsky/849eae74c1e60cc7f9c8 to your computer and use it in GitHub Desktop.
Passing 2d array as a pointer to function.
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> | |
void doit(int ** s , int row, int col) | |
{ | |
int i, j; | |
for (i = 0; i < row; i++){ | |
for (j = 0 ;j < col; j++) | |
printf("%d ", s[i][j]); | |
printf("\n"); | |
} | |
} | |
int main() | |
{ | |
int i, j; | |
int row = 4, col = 10; | |
int **c = (int**) malloc(sizeof(int*) * row); | |
for (i = 0; i < row; i++) | |
*(c+i) = (int*) malloc(sizeof(int) * col); | |
for (i = 0; i < row; i++) | |
for (j = 0; j < col; j++) | |
c[i][j] = i * j; | |
doit(c, row, col); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment