I created a function which takes 2 parameters (Name of the array, Size of the array) and what I did was take the max element of the array minus the minimum. But what i want to do now is create the same function using pointers, but i always get a result which is 0 for some reason. Here's the code:
#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;
const void pntArray(int arrName[], unsigned sizeOfArray);//The first function which takes the size of the array and the array name and prints the sub of the max-min
void pntTheArray(int *(arrName), unsigned sizeOfArray);//Version of the first function, using pointers
int main()
{
int someArr[3]={7,2,6};
int pointerArray[5]={7,6,5,4,10};
pntArray(someArr, 3);//Example of the function without the pointers
pntTheArray(someArr, 3);//Example of the function with the pointers
}
void pntTheArray(int *arrName, unsigned sizeOfArray){
int max = 0;
int min = 999999;
for (int x = 0;x<sizeOfArray;x++){
if (*arrName+x>max){
max = *arrName;
}
if(*arrName+x<min){
min = *arrName;
}
}
cout<<"The maximum element minus the the minimum element is: "<<(unsigned)(max-min)<<endl;
}
const void pntArray(int arrName[], unsigned sizeOfArray){
int max=0;
int min = 999999;
for (int x = 0;x<sizeOfArray;x++){
if(arrName[x]>max){
max = arrName[x];
}
if (arrName[x]<min){
min = arrName[x];
}
}cout<<"The maximum element minus the the minimum element is: "<<(unsigned)(max-min)<<endl;}
I want to make a version of the first array, basically. So where's the mistake that i'm making in order to get only 0 as a result for the second function?