Skip to content

Commit

Permalink
added 9.23 and improved 9.24
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Dec 2, 2014
1 parent f8e3c3f commit df8d06a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 8 additions & 0 deletions ch09/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,11 @@ FIXED: (changed the `while` loop)
```
while (iter++ != mid)
```

## Exercise 9.23:
>In the first program in this section on page 346, what would
the values of val, val2, val3, and val4 be if c.size() is 1?

same value that equal to the first element's.

## [Exercise 9.24](ex9_24.cpp)
15 changes: 5 additions & 10 deletions ch09/ex9_24.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
//! @Alan
//! @Alan @pezy
//!
//! Exercise 9.24:
//! Write a program that fetches the first element in a vector using at,
//! the subscript operator, front, and begin. Test your program on an empty vector.
//!
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>


int main()
{
std::vector<int> v;
std::cout
//<< v.at(0); //an exception was thrown
//<< v[0]; //nothing happened
//<< v.front(); //nothing happened
<< *v.begin(); //nothing happened
std::cout << v.at(0); // terminating with uncaught exception of type std::out_of_range
std::cout << v[0]; // Segmentation fault: 11
std::cout << v.front(); // Segmentation fault: 11
std::cout << *v.begin(); // Segmentation fault: 11
return 0;
}

0 comments on commit df8d06a

Please sign in to comment.