CS253 IQ 11
Show Main.IQ11 as a slide show.
Which of these is a valid declaration?
template <int I, typename T = long double>
class Foo { };
template <class C, long L, bool B = false>
class Foo { };
template <int *IP> class Foo { };
- All of the above
template <double D> class Foo { };
Everything but double D
.
You can pass double
as a type, but not as a value.
What will this code produce?
vector<int> v = {2,3,5,7};
for (auto it = v.front(); it != v.back(); ++it)
cout << it;
23456
235
2357
23456
234567
- None of the above
.front()
and .back()
return references to values,
not iterators.
What will this code produce?
vector<int> v = {1,2,3};
cout << v.end() - v.begin() << endl;
3
123
2
3
- Depends on the size of an
int
.
- It will not compile.
v.end()
“points” one past the last element,
not to last element.
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>'})
2413
1234
123
- It depends on where the tree nodes are allocated.
- None of the above.
You can’t use <
on a set::iterator
Fine, what will this code produce?
set<int> s = {2,4,1,3};
for (auto it = s.begin(); it != s.end(); ++it)
cout << *it;
1234
2413
1234
123
- It depends on where the tree nodes are allocated.
- None of the above.
Sets are sorted.