fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define LINHA 3
  4. #define COLUNA 4
  5.  
  6. void matriz_ponteiro(int **mtr, size_t linhas, size_t colunas) {
  7. for (int lin = 0; lin < linhas; lin++) {
  8. for (int col = 0; col < colunas; col++) printf("\t%d", mtr[lin][col]);
  9.  
  10. printf("\n");
  11. }
  12. }
  13.  
  14. int main () {
  15. int **mtr = malloc(LINHA * sizeof(*mtr));
  16. for (int lin = 0, cont = 0; lin < LINHA; lin++) {
  17. mtr[lin] = malloc(COLUNA * sizeof(*mtr[lin]));
  18. for (int col = 0; col < COLUNA; col++) mtr[lin][col] = cont++;
  19. }
  20. matriz_ponteiro(mtr, LINHA, COLUNA);
  21. }
  22.  
  23. //https://pt.stackoverflow.com/q/165524/101
Success #stdin #stdout 0s 4180KB
stdin
Standard input is empty
stdout
	0	1	2	3
	4	5	6	7
	8	9	10	11