Chapter 2 Flashcards

1
Q
  1. You want to declare an integer variable called myVar and assign it the value 0. How can you accomplish this?
    a. declare myVar as 0;
    b. myVar = 0;
    c. int myVar = 0
    d. int myVar = 0;
A

b. myVar = 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

2 You need to make a logical comparison where two values must return true in order for your code to execute the correct statement. Which logical operator enables you to achieve this?

a. AND
b. |
c. &
d. &&

A

d. &&

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What kind of result is returned in the condition portion of an if statement?
    a. Boolean
    b. Integer
    c. Double
    d. String
A

a. Boolean

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What are the keywords supported in an if statement?
    a. if, else, else-if, return
    b. if, else, else if
    c. if, else, else if, break
    d. if, else, default
A

b. if, else, else if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. In the following code sample, will the second if structure be evaluated?
    bool condition = true;
                if(condition)
                   if(5
A

a. Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. If you want to iterate over the values in an array of integers called arrNumbers to perform an action on them, which loop statement enables you to do this?
    a. foreach (int number in arrNumbers)
    {
    }
    b. for each (int number in arrNumbers)
    {
    }
    c. for (int i; each i in arrNumbers; i++)
    {
    }
    d. foreach (number in arrNumbers)
    {
    }
A

a. foreach (int number in arrNumbers)
{
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. What is the purpose of break; in a switch statement?
    a. It causes the program to exit.
    b. It causes the code to exit the switch statement.
    c. It causes the program to pause.
    d. It causes the code to stop executing until the user presses a key on the keyboard.
A

b. It causes the code to exit the switch statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What are the four basic repetition structures in C#?
    a. for, foreach, loop, while
    b. loop, while, do-for, for-each
    c. for, foreach, while, do-while
    d. do-each, while, for, do
A

c. for, foreach, while, do-while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
9.	How many times will this loop execute?
                int value = 0;
                do
                {
                   Console.WriteLine (value); 
                } while value > 10;
a.	10 times
b.	1 time
c.	0 times
d.	9 times
A

b. 1 time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
E1.	Which of the following is NOT a comparison operator?
a.	!=
b	=
c.	>
d.	<
A

b =

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

E2. Which of the following is the correct syntax for executing the following statements in an if statement?
Console.WriteLine(“In an if statement”);
Console.WriteLine();
a.
bool condition = true;
if(condition)
Console.WriteLine(“In an if statement”);
Console.WriteLine();
Console.WriteLine(“Outside the if statement”);
b.
bool condition = true;
if(condition)
{
Console.WriteLine(“In an if statement”);
Console.WriteLine();
}
Console.WriteLine(“Outside the if statement”);
c.
bool condition = true;
if(condition)
{
Console.WriteLine(“In an if statement”);
Console.WriteLine();
Console.WriteLine(“Outside the if statement”);
}
d.
bool condition = true;
if(condition)
{
Console.WriteLine(“In an if statement”);
}
Console.WriteLine();
Console.WriteLine(“Outside the if statement”);

A
b.
   bool condition = true;
    if(condition)
    {
         Console.WriteLine("In an if statement");
         Console.WriteLine();
    }
    Console.WriteLine("Outside the if statement");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

E3. Which of the following looping structures must end with a semicolon?

a. for
b. foreach
c. do-while
d. while

A

c. do-while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

E4. How do you handle multiple switch statements with one condition in a switch structure?
a. Remove the colon after the condition.
b. Enclose all the code statements you want executed together in curly braces.
c. Create separate switch statements.
d. Omit the break; statement.
structure?

A

d. Omit the break; statement.

structure?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

E5. In a for statement, when does the incrementing of the counter take place?

a. On the last iteration only
b. At the end of each iteration
c. On the second and subsequent iterations only
d. At the end of the iteration and after the comparison

A

b. At the end of each iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

E6. When can you assign a value to a variable?

a. During creation only
b. Only runtime in code
c. During declaration
d. Only at design time when writing the code

A

c. During declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

E7. How can you tell when a statement has ended in C#?

a. Using the end of line character
b. Using the carriage return character
c. Using the colon
d. Using the semicolon

A

d. Using the semicolon

17
Q

E8. What is a declaration statement used for in C#?

a. To declare a variable name
b. To declare a variable name and data type
c. To declare the beginning of program execution
d. To declare the beginning of a function

A

b. To declare a variable name and data type

18
Q

E9. Which of these is not a valid C# statement?

a. ;
b. int myVar;
c. string string;
d. Console.WriteLine(“Hello world”);

A

c. string string;

19
Q

E10. What is one common characteristic of complex statements?

a. They contain only complex statements.
b. They enclose statements in curly braces.
c. They enclose statements in parentheses.
d. They use tabs and other white space to tell the compiler where statements start and end.

A

b. They enclose statements in curly braces.

20
Q

E11. In a complex if, else if structure, what keyword can be used to denote the final condition?

a. end if
b. endif
c. default
d. else

A

d. else