CSCI
tutorial05.pptx

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

• 28

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

CSCI1120 Introduction to Compu ting Using C++ Tutorial 5 Li Le SHB 1013 lil @cse.cuhk.edu.hk 1

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

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
Outline Solutions to Selected Questions from Past Mid term Exam Papers 3

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

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
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

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

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
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 .

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

This is the end of the preview. Sign up to access the rest of the document.
• Fall '15

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern