🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C# Workshop - Week 3 Review Questions

Started by
10 comments, last by JWalsh 16 years, 11 months ago
.NET Book Zero Chapters 7, 8, 9, and 10 Review Questions Greetings everyone. Each week I will post review questions and exercises in the weekly forum. Please try and answer them by yourself; either as you're reading over the chapters, or afterwards if you prefer. Once you've done so, feel free to look over the answers provided by others and submit your own answers if you've not yet seen them posted. Discussion about the review questions and answers is encouraged for clarification. Finally, experienced C# programmers may feel free to post quiz-like questions and exercises of their own.
  1. What are the primary operators in C#?
  2. What are the conditional operator in C#?
  3. Which two categories of operators have right to left associativity?
  4. What is operator precedence?
  5. What determines which operators get evaluated first if two or more have the same precedence?
  6. What operator can you use to change the precedence of other operators?
  7. True or False, assigning a value to a variable returns a value?
  8. How many arguments does a unary operator have?
  9. An expression must always be placed before or after the unary operator symbol?
  10. What is the result of the - operator when applied to a number?
  11. Can the ! operator be applied to any other type besides Boolean value?
  12. What is the result of the ! operator when applied to a Boolean value?
  13. Which types can use the ~ unary operator, and what does it do?
  14. The + operator is defined for which data type in addition to all numerical types?
  15. What do the << and >> operators do?
  16. When a signed type is shifted to the right, is the most significant bit set to the value of the sign bit, or is it set to 0?
  17. The relational operators <, >, <=, and >=, as well as the equality operators == and != all return a value of what type?
  18. True for false, the equality operators == and != CANNOT be used in C# to compare strings.
  19. What are the Logical operators in C#?
  20. What happens when the logical operators are applied to integral values?
  21. What happens with the logical operators are applied to Boolean values?
  22. What are the only data types which can be combined with the conditional operators || and &&?
  23. What is the difference between the logical operators and the conditional operators when working with Boolean types?
  24. In C# is it possible to mix integer and Boolean types with the logical operators?
  25. What is the only operator with 3 operands? What does it do?
  26. What does compound assignment mean in C#, and what are the compound assignment operators?
  27. The keyword 'if' must be followed by parenthesis with what kind of expression inside?
  28. If more than one statement needs to be executed as a result of an if-statement, how can those statements be grouped?
  29. When is an 'else' statement evaluated?
  30. Can if and else statements be nested inside of each other?
  31. When you declare variables within a block, when are they no longer visible?
  32. It is possible to declare a variable within a block with the same name as a variable in a higher scoped block?
  33. It is possible to declare a variable within a block with the same name as a variable in a similar (adjacently, or sibling) scoped block?
  34. When using C# Switch statements, what must be true for execution to "fall through" one case into the next case.
  35. If a goto statement is provided at the end of switch case, is a break statement still necessary?
  36. What are the possible types allowed in the expression at the top of a switch statement?
  37. Is it possible to put string expressions in a switch-state comparison?
  38. What internal technique makes it efficient for string comparisons in C#?
  39. What does a while-statement do?
  40. What's the difference between a while-statement and a do-while-statement?
  41. What is true of the evaluated expression in a while or do-while statement? That is, what type must it be?
  42. Explain the three parts involved in the first line of a for-statement?
  43. What does a continue and break statement do within all iterative statements (for, while, do-while, and foreach)?
  44. If a variable is created within the initializer section of a for-loop, can it be used outside the for-loop after the loop is terminated?
  45. In a foreach block, what is true of the iteration variable? As a result, is it possible to initialize the values in an array by using a foreach statement?
  46. What interface must be implemented in order for a type to work with the foreach statement?
  47. How do you define a label for a goto statement?
  48. Is it possible to goto a label which is not in either the current block or a parent block?
  49. Are stacks shared between threads in an application, or does each thread have its own stack?
  50. What types of data are stored on a stack?
  51. When is memory allocated on the stack for local variables in a method? When is the memory freed?
  52. Are heaps shared between threads in an application, or does each thread have its own stack?
  53. Where is a local string reference stored? Where is the actual string data stored?
  54. Is the amount of space required on the stack for a string consistent or dynamic?
  55. Can the address (the value in a reference) be directly manipulated or used in an arithmetic expression?
  56. What happens to a memory block on the heap which no longer has any references to it?
  57. When you declare variables of all the simple numeric types, is the variable stored on the stack, or the heap?
  58. When you create an object, is the reference to the object stored on the stack or the heap? How about the data for the object itself?
  59. What is a string with no characters referred to as?
  60. What keyword is used to tell a reference variable there is no memory allocated for it on the heap.
  61. Can null be used in comparisons to determine if a reference variable has memory allocated for it?
  62. Is it possible to set a value-type to null, why or why not?
  63. What is an Array?
  64. What do you call each item in an array
  65. What is the acceptable range of indices into an array
  66. Where is the initial square bracket (not the one when allocating) placed in an array declaration? Can it have any numbers in it?
  67. What operator do you use to allocate memory for an array?
  68. What number do you put in the brackets present when allocating memory for an array?
  69. Are array elements allocated on the stack or the heap?
  70. What happens at run-time if you just a negative index, or an index that is larger than the maximum allowed index?
  71. What is the implicit base class for all arrays?
  72. What does Petzold consider to be the most important property of an array?
  73. Is it possible to allocate memory for the array when declaring it?
  74. Is it possible to initialize the values in an array as part of the declaration?
  75. If you initialize the values in an array as part of the declaration are you required to put the number of elements you're allocating?
  76. If you initialize the values in an array as part of the declaration are you required to use the new operator?
  77. If you initialize an array of reference types, what is the initial value in each element?
  78. How many types of multi-dimensional arrays does C# allow?
  79. For multi-dimensional arrays, how do you reference a specific element?
  80. For a multi-dimensional array, what value is returned from the Length property?
  81. What does the Rank property of an array tell you?
  82. What is the functional difference between multi-dimensional array, and jagged arrays?
  83. True or False, because jagged arrays are essentially arrays of arrays, they require multiple 'new' invocations, one for the main variable, and one for each element in each sub-dimension?
  84. True or false, You can initialize the values of an entire jagged array during declaration by putting 'new' and nested brackets in the correct locations?
Cheers! [Edited by - JWalsh on July 21, 2007 10:53:31 PM]
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Advertisement
Posting a few of what I hope are correct answers. Can we get a Week 2 Answer Thread also? Or should we PM you for the answers jwalsh?

1. What are the primary operators in C#?

(x) parenthesis, x.y dot operator(period), f(x) function call with f the function, a[x] array index and access, x++ x-- post increment and decrement operators, new, checked, unchecked, typeof, sizeof
2. What are the conditional operator in C#?

And(&&), Or(||), Conditional (?:)
3. Which two categories of operators have right to left associativity?

Conditional (?:) and Assignment (=, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |=, ??)
4. What is operator precedence?

The order in which operators are evaluated
5. What determines which operators get evaluated first if two or more have the same precedence?

associativity
6. What operator can you use to change the precedence of other operators?

Parentheses ()
7. True or False, assigning a value to a variable returns a value?

True
8. How many arguments does a unary operator have?

One
9. An expression must always be placed before or after the unary operator symbol?

after
10. What is the result of the - operator when applied to a number?

Negative of the number
11. Can the ! operator be applied to any other type besides Boolean value?

no
12. What is the result of the ! operator when applied to a Boolean value?

True=False, False=True
13. Which types can use the ~ unary operator, and what does it do?

Bit wise compliment-changes all ones to zeros, zeros to ones, used by int, uint, long, ulong
14. The + operator is defined for which data type in addition to all numerical types?

string
15. What do the << and >> operators do?

Left and right bit shift
16. When a signed type is shifted to the right, is the most significant bit set to the value of the sign bit, or is it set to 0?

Set to the value of the sign bit
17. The relational operators <, >, <=, and >=, as well as the equality operators == and != all return a value of what type?

Boolean
18. True for false, the equality operators == and != CANNOT be used in C# to compare strings.

False
19. What are the Logical operators in C#?

And, Or, Xor

[Edited by - shawnre on July 29, 2007 11:05:54 PM]
Quote: Original post by shawnre
9. An expression must always be placed before or after the unary operator symbol?

Before or after


From what I gathered, the unary operators always come before the expression. Can someone confirm this?

Edit: I just had a look at the specification, guess it depends on what you mean by "unary operators". If unary means all operators taking only one argument, then it's before / after, but if you mean only the operators listed in the "Unary" row in the tables on page 68 (Petzold) and 107 (specification) , then the expression must be on the right side of the operator.

Again, this isn't the definite answer, just my own personal answer to question 9.
Are we supposed to provide our answers? If that is the case, then I uploaded my answers here (I think it's a bit easier to read/write in .doc and pdf.).
CK, I didn't have time to look over your answers, but I like the formatting of your website.

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
CKolding, I had a quick look at some of your answers, question 40 needs to be looked at again.

40. What's the difference between a while-statement and a do-while-statement?

The difference is only the way its typed and shown.

This is wrong.

They do not do the same thing, a do-while statement is always executed at least once whereas a while statement may not be executed if the expression in the while evaluates to false.

The rest of your answers seem similar to mine.
How about them apples?
Quote: This is wrong.

They do not do the same thing, a do-while statement is always executed at least once whereas a while statement may not be executed if the expression in the while evaluates to false.


Thanks a lot for correcting me on that one - I will edit my answers right away. Would've caused me a lot of trouble later on if I didn't realize why that darn for-loop didn't behave as I wanted it to.
Posted my questions/answers on my developer blog:
For this week:
http://shadowprofiles.net/whatever/?p=11
Quote: Original post by shawnre
2. What are the conditional operator in C#?

And(&), Or(|), Conditional (?:)


Just thought I'd point out that the 'and' and 'or' operators you are looking for are actually && and || as in

if (a && b) // if a and b
if (a || b) // if a or b

Using the single & and | are actually bitwise operators.
Thanks Nick, corrected that.

This topic is closed to new replies.

Advertisement