1: Well, yes, you can use a pointer to index an array, but you don't need the star.
Code:
mingw32-g++.exe -Wall -fexceptions -pedantic-errors -pedantic -Wfatal-errors -std=c++98 -g -c C:\Users\jk\Desktop\hello\main.cpp -o obj\Debug\main.o
C:\Users\jk\Desktop\hello\main.cpp: In function 'int myFunc(int*, int)':
C:\Users\jk\Desktop\hello\main.cpp:11:27: error: invalid type argument of unary '*' (have 'int')
sum = sum + *arr[i];
^
compilation terminated due to -Wfatal-errors.
2: It's more complicated than the pointer option. Details here.
3: No, but you might prefer it to other options.
Code:
int myFunc(int *first, int *last)
{
int sum = 0;
while (first != last) { sum += *first++; }
return sum;
}
#include <iostream>
int main()
{
int arr[] = {1,2,3,4,5};
int sum = 0;
sum = myFunc(arr, arr + sizeof(arr) / sizeof(arr[0]));
std::cout << sum << std::endl;
}
4: No... if it was the compiler would tell you.