c - Trying to access array elements: subscripted value is not an array, pointer, or vector -


i'm trying write function adds elements in array. unfortunately, every time try access array elements, abovementioned error message when compile. going on?

#include <stdio.h>  int arraysum(ar, number) {     int x = 0;     int i;     (i = 0; < number; i++) {         x += ar[i];     }     return x; }   int main (void) {     int ar[4] = {3,6,9,12};     int number = 4;      printf("the sum %i",arraysum(ar[4], number));      return 0; } 

this code should like:

#include <stdio.h>  int arraysum(int ar[], int number) {     int x = 0;     int i;     (i = 0; < number; i++) {         x += ar[i];     }     return x; }   int main (void) {     int ar[4] = {3,6,9,12};     int number = 4;      printf("the sum %i",arraysum(ar, number));      return 0; } 

you can test here http://codepad.org/a2dzzzsg

you forgot declare types of arraysum() parameters, compiler did not know expect @ first, , tried pass ar[4] function, not valid index vor array , would, if had 5 members, pass 1 int value , not whole array.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -