CS253: Software Development with C++

Fall 2018

IQ 11

CS253 IQ 11

See this page as a slide show

Which of these is a valid C++11 declaration?

  1. template <int I, typename T = long double>
    class Foo { };
  2. template <class C, long L, bool B = false>
    class Foo { };
  3. template <int *IP>
    class Foo { };
  4. All of the above
  5. template <double D>
    class Foo { };

What will this code produce?

vector<int> v = {2,3,5,7};
for (auto it = v.front(); it != v.back(); ++it)
    cout << it;
23456
  1. 235
  2. 2357
  3. 23456
  4. 234567
  5. None of the above

C: .front() and .back() yield references, not iterators

What will this code produce?

vector<int> v = {1,2,3};
cout << v.end() - v.begin() << endl;
3
  1. 123
  2. 2
  3. 3
  4. Depends on the size of an int.
  5. It will not compile.

What will this code produce?

set<int> s = {2,4,1,3};
for (auto it = s.begin(); it < s.end(); ++it)
    cout << *it;
c.cc:2: error: no match for 'operator<' in 'it < s.std::set<int>::end()' 
   (operand types are 'std::_Rb_tree_const_iterator<int>' and 
   'std::set<int>::iterator' {aka 'std::_Rb_tree_const_iterator<int>'})
  1. 2413
  2. 1234
  3. 123
  4. It depends on where the tree nodes are allocated.
  5. None of the above.

E: You can’t use < on a set::iterator

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-10-31T20:33

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building