Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created November 2, 2010 21:11
Show Gist options
  • Select an option

  • Save fsouza/660304 to your computer and use it in GitHub Desktop.

Select an option

Save fsouza/660304 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main () {
int i, j, tamanho_vetor = 5, tamanho_string = 30;
int *vetor;
int **matriz;
char *string = "LINGUAGEM DE PROGRAMACAO";
vetor = (int *)malloc(tamanho_vetor * sizeof(int));
for (i = 0; i < tamanho_vetor; i++) {
*(vetor + i) = i;
}
matriz = (int **)malloc(tamanho_vetor * sizeof(int *));
for (i = 0; i < tamanho_vetor; i++) {
*(matriz + i) = (int *)malloc(tamanho_vetor * sizeof(int));
for (j = 0; j < tamanho_vetor; j++) {
*(*(matriz + i) + j) = i;
}
}
// Imprimindo ...
for (i = 0; i < tamanho_vetor; i++) {
printf("vetor[%d] = %d\n", i, *(vetor + i));
}
printf("\n\n");
for (i = 0; i < tamanho_vetor; i++) {
printf("Linha %d: ", i);
for (j = 0; j < tamanho_vetor; j++) {
printf("%d ", *(*(matriz + i) + j));
}
printf("\n");
}
printf("\n\n");
printf("String: %s.\n\n", string);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment