# Review Questions

 1: How are the following expressions evaluated in C#: 5 + 10 * 2 5 * 6 / 3 12 / 4 * 6 20 % 8 myIntVariable++ --myIntVariable 2: Suppose you need to add number1 and number2 together and multiply this result by number3. The first attempt: ` number1 + number2 * number3 ` gave a wrong result. Fix the problem. 3: The following expression is correct but unclear for the reader of the code. Make it more clear. ` num1 + num2 / num3 * num4 num5 * num6 / num7 ` 4: Write an if statement that checks whether a number (call it myNumber) of type int is even or odd. Only if myNumber is even should it write "The number is even" onscreen. 5: What is the type of the following expression if weight is of type short? ` -weight ` 6: Improve the clarity of the following statement by separating it into three statements without altering the effects of the code: ` totalBacteria = ++bacteriaInBody1 + bacteriaInBody2++; ` 7: Draw a flowchart that illustrates the following logic. A person wants to go for a walk. If it rains, he asks his wife if they have an umbrella. If they have an umbrella he will go out; otherwise, he will stay inside. If it does not rain, he will go out whether they have an umbrella or not. 8: Which construct would be suitable to represent the following values in a C# program: { Red, Green, Blue, Yellow, Purple} 9: Write a statement that prints the following text on the console (including the quotation marks)? ` And then he said: "This is a great moment" ` 10: Suppose myString contains 20 characters. Write an expression that returns a sub-string from myString beginning at character number 10 and including 5 characters. 11: Suppose distance1 is 100, distance2 is 200, and distance3 is 400. Write a statement that uses embedded formatted numbers to include the three variables in a string so that the final text reads ` The first distance is 100 meters, the second distance is 200 meters and the third distance is 400 meters. `

C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon