Skip to content

Instantly share code, notes, and snippets.

@lesovsky
Created July 12, 2015 12:06
Show Gist options
  • Save lesovsky/849eae74c1e60cc7f9c8 to your computer and use it in GitHub Desktop.
Save lesovsky/849eae74c1e60cc7f9c8 to your computer and use it in GitHub Desktop.
Passing 2d array as a pointer to function.
#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