What happens when you attempt to compile and run the following code?

Last Updated on December 5, 2021 by Admin 2

What happens when you attempt to compile and run the following code?

#include <deque>
#include <vector>
#include <iostream>
using namespace std;
template<typename T>
int calculate(T start, T end)
{
int s = 0;
while (start != end)
s+= *start; start++;return s;
}
int main ()
{
int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};
vector<int>v1(t, t+5);
deque<int>d1(t+5, t+10);
cout<<calculate(t,t+10)<<” “;
cout<<calculate(v1.begin()+1,v1.end()?2)<<” “;
cout<<calculate(d1.rbegin()+1,d1.rend()?2)<<” “;
cout<<calculate(t[0],t[10])<<” “;
cout<<endl;
return 0;
}

  • compilation error
  • runtime exception
  • program outputs 55 5 17 55
  • program outputs 55 5 17 0
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments