Skip to content

Commit

Permalink
Fix the answer to exercise 5.13
Browse files Browse the repository at this point in the history
ix under case "1" is not initialized, UB will happen. 
So bring the definition of ix out of switch statement.
  • Loading branch information
jianhua1in authored Jun 13, 2018
1 parent 13cffd3 commit 0812cf0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ch05/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ Colloquial term used to refer to the problem of how to process nested if stateme
}
(b) // Error: control bypass an explicitly initialized variable ix.
unsigned index = some_value();
int ix;
switch (index) {
case 1:
int ix;
ix = get_value();
ivec[ ix ] = index;
break;
default:
Expand Down

0 comments on commit 0812cf0

Please sign in to comment.