{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

tutorial05.pptx - CSCI1120 Introduction to Compu ting Using...

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

View Full Document Right Arrow Icon
CSCI1120 Introduction to Compu ting Using C++ Tutorial 5 Li Le SHB 1013 lil @cse.cuhk.edu.hk 1
Background image of page 1

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

View Full Document Right Arrow Icon
Reminder of Quiz Date: Tue 18 Oct 2016 Time: 3:30pm - 4:30pm (1 hr) Venue: ERB 803 Scope: lec01 - lec06 Format: close-book, close-notes, written 2
Background image of page 2
Outline Solutions to Selected Questions from Past Mid term Exam Papers 3
Background image of page 3

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

View Full Document Right Arrow Icon
Problem 1 (a) int x = 0; x = 4++; cout << x; Is this code valid? What is the output of this code? Analysis: 4 is a constant . We can only apply "+ +" and "--" operators to variables. Result: Invalid 4
Background image of page 4
Problem 1 (b) int x = 10, z = 0; int y = ++x + z--; cout << "x = " << x << ", z = " << z << endl; cout << "y = " << y << endl; What is the output of this segment? Analysis: “++” “--” Prefix : returns value after increment/decrement Postfix : returns value before increment/decrement Result: 5
Background image of page 5

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

View Full Document Right Arrow Icon
Problem 1 (c) int a = 4; if (a > 0) cout << "A"; cout << "B"; else cout << "C"; cout << "D"; Result: Invalid Is this code valid? What is the output of this code? Analysis: The syntax of if-else statement only allows one single statement after the condition and before the "else" keyword . However, here we have two statements. How to make it valid? { } 6
Background image of page 6
Problem 1 (d) cout << "////// \\\\\\"; Is this code valid? What is the output of this code? Analysis: String constant must be enclosed in double quotes within one line . Result: Invalid How to make it valid? String constant can extend to more than a single line of code by putting a backslash sign (\) at the end of each unfinished line .
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}