Trying to implement a bool function to check if a certain value exists in an array or not but it checks first index [0] only, I tried the same way manually in main function and it worked but I need it to be in a separate function.
#include <iostream>
using namespace std;
bool ifExist(int arr[], int num){
    for(int i=0; i<sizeof(arr)/sizeof(*arr); i++){    
        if(arr[i] == num){
             return true;
        }
    }
    return false;
}
int main()
{
    int num;
    cin>>num;
    int arr[5]={1,2,3,4,5};
    cout<<ifExist(arr,num);
    return 0;
}
 
    