why is this code producing a segmentation fault when i try to output the value ?
the segmentation fault is being caused due to the line
cout << *rit_j;
void chef(vector<int>vec)
{
int count=0;
vector<int>::iterator bit = vec.begin();
vector<int>::iterator eit=vec.end();
if(*bit != *eit)
{
sort(bit,eit);
vector<int>::iterator rit_i,rit_j,initial = vec.end();
--rit_i;--rit_j;--initial;
cout << *rit_i;
}
}
In this declaration:
only
initial
is initialized withvec.end()
. To make it do what I think you expect, you have to writeor
or something to that effect.