Get 1 week of unlimited access
Class Notes (1,033,362)
US (405,781)
CSCI (23)
CSCI 10 (18)
Lecture 12

CSCI 10 Lecture 12: CSCI 10 – Day 12Premium

2 pages54 viewsFall 2016

Department
Computer Science
Course Code
CSCI 10
Professor
Bannister
Lecture
12

Page:
of 2
CSCI 10 Day 12
CALL-BY-REFERENCE
Announcements
-(W 4 link fixed! )t’s due Friday
Example 18
Void error_msg(string s) {
cout << ERROR:  << s << endl;
exit(1); // program ended with exit code: 1
}
Int main() {
error_msgSomething bad!;
return 0;
}
:: - the separator (between area code(namespace) and body)
Error:
int f (int x) {
if (x > 0) {
return 1;
}
if x <=  { // compiler doesn’t know that there’s only two possible cases
return -1;
}
}
Correct:
int f (int x) {
if (x > 0) {
return 1;
} else { // x <= 0
return -1;
}
}
void zero (int& u, int& v, int& w) // you can drop the variable names?? {
u, v, w = 0;
}
int main () {
int x = 7;
int y = 8;
int z = 9;
zero(x, y, z);
cout << x <<   << y <<   << z << endl;
find more resources at oneclass.com
find more resources at oneclass.com
return 0;
}
Example 20
int main () {
int x = 7;
int y = 8;
int z = 9;
zero(x, y, 1); // 1 is stored in a special memory and not passed into the
function
cout << x <<   << y <<   << z << endl;
return 0;
}
Converting variable types (casting)
- static_cast<double>//int Looks ugly because )’m doing something
bad and asking permission to do it)
find more resources at oneclass.com
find more resources at oneclass.com

Loved by over 2.2 million students

Over 90% improved by at least one letter grade.