



























Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!




























Acesso através dos índices. Atribuição através dos índices. valor = placar[0]; /valor = 23.48/ num = placar[5]; /num = 23.60/ placar[3] = 41.00; 0 1 2 3 4 5 6 7
Acesso através dos índices. Atribuição através dos índices. valor = placar[0]; /valor = 23.48/ num = placar[5]; /num = 23.60/ placar[3] = 41.00; 0 1 2 3 4 5 6 7
Comandos de Repetição podem ser utilizados para atribuir valores ao vetor por meio dos índices #include <stdio.h> int main() { int i; int vetor[5]; for (i=0;i<5;i++) vetor[i] = 10; return 0; } 0 1 2 3 4 10 10 10 10 10 Índices vetor[5]
Atribuição entre vetores (INCORRETO)
Acesso indevido (Segmentation Fault)
Definição de tamanho em tempo de execução #include <stdio.h> int main() { int n; printf (“Digite a quantidade de notas: ”); scanf (“%d”, &n); int notas[n]; for (i = 0; i < n; i++) scanf (“%d”, ¬as[i]); printf (“Notas: ”); for (i = 0; i < n; i++) printf (“%d ”, notas[i]); return 0; }
Vetores como retorno de uma função (INCORRETO) #include <stdio.h> int RetornaVetor( int vetor[], int tam) { ... return vetor; } int main() { ... RetornaVetor(vet, 5); return 0; }
Vetores como retorno de uma função (CORRETO) #include <stdio.h> int RetornaVetor( int vetor[], int tam) { ... return vetor[3]; } int main() { ... RetornaVetor(vet, 5); return 0; }
#include <stdio.h> int main() { int vet[10]; register int i; for (i = 0; i < 10; i++) scanf ("%d", &vet[i]); for (i = 0; i < 10; i++) printf ("%d ", vet[i]); printf ("\n"); return 0; }