Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    c++

    C++
    2
    2
    15
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Raghav Khemka
      Raghav Khemka last edited by avan

      #include <vector>
      #include <algorithm>
      using namespace std;
      
      int main()
      {
          vector<int> data(5,1);
          int sum {0};
      
          cout << sum << endl;
          
          for(auto element : data)
               sum += element;
          cout << sum << endl;
      
          for(auto p = ++data.begin(); p != --data.end(); ++p)
               sum += *p;
          cout << sum << endl;
        
          sum = 0;
          data.push_back(2);
          data.push_back(3);
          
          for(auto element : data)
               sum += element;
          cout << sum << endl;
      
          cout << accumulate(data.begin(), data.end(), data[0]) << endl;
      }
      

      MY question is :

      1. What does the first line of the following print?
      2. What does the Second line of the following print?
      3. What does the Third line of the following print?
      4. What does the Fourth line of the following print?
      5. What does the fifth line of the following print?
      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by

        Hey @Raghav-Khemka

        I am confused. Have you tried running it? Are you asking what the output would be if you ran it?

        Reply Quote 0
          1 Reply Last reply

        • First post
          Last post