void foo(int x) { int y = 4; x = 10; cout << x << " " << y; } int main() { int x=2, y=3; foo(x); cout << x << " " << y; return 0; }
void foo(int &x) { int y = 4; x = 10; cout << x << " " << y; } int main() { int x=2, y=3; foo(x); cout << x << " " << y; return 0; }
void swap(int &x, int &y) { x=y; y=x; } int main() { int x=2, y=3; swap(x,y); cout << "X=" << x << " Y=" << y; return 0; }
void printMoney(int dollars, int cents = 0) { cout << dollars << " dollars and " << cents << " cents."; return; } int main() { printMoney(2,50); printMoney(4); return 0; }
x = ComputeValue(); assert(x>=0);
x = ComputeValue(); x = -1;
x = ComputeValue(); if (x>=0) { cout << "Error, value is non-negative."; exit(0); }
x = ComputeValue(); if (x<0) { cout << "Error, value is negative."; exit(0); }
x = ComputeValue(); x = 0;
void foo(int x); int main() { int x=1; cout << "Before foo, X=" << x; foo(x); cout << " After foo, X=" << x; return 0; } void foo(int x) { x = 2; cout << "In foo, X = " << x; return; }
void foo(int x); int x; int main() { x=1; cout << "Before foo, X=" << x; foo(x); cout << " After foo, X=" << x; return 0; } void foo(int x) { x = 2; cout << "In foo, X = " << x; return; }
int z; void main() { foo(z); return 0; }
void main() { int y; foo(y); return 0; }
void main() { foo(10); return 0; }
void main() { int x; foo(x); return 0; }