Advertisement
renix1

Somando com ponteiro

Feb 26th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int somaVetor(int vetor[], const int n) {
  5.     int soma = 0;
  6.     int *const finalVetor = vetor + n;
  7.     int *ponteiro = vetor;
  8.     while (ponteiro < finalVetor) {
  9.         soma += *ponteiro;
  10.         ++ponteiro;
  11.     }
  12.     return soma;
  13. }
  14.  
  15. int main (void) {
  16.     int somaVetor(int vetor[], const int n);
  17.     int vetor[10] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5};
  18.     printf("Soma = %d\n", somaVetor(vetor, 10));
  19.    
  20.     return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement