IntroToProggramming.pdf

Answer b section reference understanding arrays any

• 17

This preview shows page 4 - 6 out of 17 pages.

19. Answer: b Section Reference: Understanding Arrays Any array item can be directly accessed by using an index. In the .NET Framework, array indexes are zero-based, meaning that to access the first element of an array, you use the index 1; to access the second element, you use the index 2; and so on. In the given case, as you need to access the second element, you use the expression numbers[2].: You are writing code for a business application by using C#. You write the following statement to declare an array: int[] numbers = { 1, 2, 3, 4, 5 }; Now, you need to access the second item in this array (the number 2). Which of the following expression should you use? a) numbers[0] b) numbers[1] c) numbers[2] d) numbers[3] 20. Answer: b Section Reference: Understanding Operators The way unary increment and decrement operators work when used as part of an assignment can affect the results. In particular, when the unary increment and decrement operators are used as prefixes, the current value of the identifier is returned before the increment or decrement. On the other hand, when used as a suffix, the value of the identifier is returned after the increment or decrement is complete. When the first statement is executed, the value of x is 10. When the second statement is executed, the value of x and y are both 11. When the final statement is executed, the current value of y (11) is assigned to z before y is incremented by 1.: You are developing a C# program. You write the following code: int x = 10; int y = ++x; int z = y++; What will be the value of the variable z after all the above statements are executed?

Subscribe to view the full document.

21. Answer: b Section Reference: Understanding Operators To evaluate this expression, you have to take into account operator precedence. The operators * and / have a higher precedence than + and -. You can also write this expression as 6 + ((4 * 4) / 2) - 1 This simplifies to, 6 + (8) - 1, resulting in 13.: You are developing a C# program. You write the following code line: int x = 6 + 4 * 4 / 2 - 1; What will be the value of the variable x after this statement is executed? 22. Answer: b Section Reference: Understanding Repetition Structures The control will enter the loop only once. At the end of the first iteration, the condition will fail (because the number 6 is greater than the number 5) and the loop will terminate.: You are developing a C# program. You write the following code: int i = 6; do { if (i == 3) break; Console.WriteLine("The value of i = {0}", i); i++; } while (i <= 5); How many times will the control enter the while loop? a) 0 b) 1 c) 2
• Spring '16
• Antin
• Control flow, Common Intermediate Language

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