st04-functions

st04-functions - CSC 1111 Introduction to Computing using...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ Functions (Self-test questions)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Tracing function calls #include <iostream> using namespace std; void f1() { cout << "A"; } void f2() { cout << "B"; f1(); cout << "C"; } void f3() { f1(); cout << "D"; f2(); } int main() { f1(); f2(); f3(); return 0; } // What's the output? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Background image of page 2
3 Tracing function calls #include <iostream> using namespace std; int f1(int y) { int x = y; y++; cout << x << endl; return y; } int main() { int x = 10; x = f1(x); cout << x << endl; return 0; } // What's the output? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Tracing function calls #include <iostream> using namespace std; int f1(int x) { cout << "f1: " << x << endl; return x * x; } int f2(int x) { cout << "f2: " << x << endl; return f1(x) + x; } int main() { // What does this print? cout << f2(5) << endl; // What does this print? cout << f1(f1(2))
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 12

st04-functions - CSC 1111 Introduction to Computing using...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online