ee322c_a1_v2 - EE 322C Data Structures Fall 2008...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EE 322C Data Structures Fall 2008 Instructor: Dr. Ramesh Yerraballi Date: Sep. 4, 2008 Grader: Senthil K Chellappan Due-Date: 11:55 PM, Sep. 10, 2008 Quiz 1 Full Name (Last, First): Solutions to Quiz 1 All the code snippets in this assignment are Java programs unless specified otherwise. Total points available: 65 . Strategy: Check for compilation errors. If errors exist, provide a fix else produce the output of the program. You do not need to check for run-time errors. Submission: Please type your answers as a Word doc or txt or pdf and upload it electronically on Blackboard. Tip: Attempt the problems without a computer first, and then verify your reasoning with the actual program output. This will help you reason out problems during the tests. 1. Refresher a) Are the if-statements syntactically correct in C/C++? In Java? (4 points) int i = 0, j = 1, k = 2; if (i < j && j < k) { } if (i < j < k) { } Answer: The first if statement is syntactically correct in both C++ and Java. The second if statement is syntactically correct in C++ because i < j is evaluated first to return a bool ( true ) which can be cast to an int (1) . Then (1 < k) is compared and a bool is returned. In Java, operator < is not defined on a boolean and a boolean cannot be type cast to any other type. b) What gets printed after executing the following code? [Hint: Operator &&, || evaluation ] (3 points) int i = 0, j = 1, k = 2; if (i > j && j++ < k) { } System.out.println(j); Answer: The if statement evaluates i > j first to return false and no more evaluation is (needs to be) done because the operator && evaluates to false if any of the sub-expressions evaluate to false . Similarly, || evaluates to true if any of the sub-expressions is true and short circuits....
View Full Document

Page1 / 4

ee322c_a1_v2 - EE 322C Data Structures Fall 2008...

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

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