Core Programming Flashcards

1
Q

int

A

4 bytes / 32 bits
can store whole numbers only
from -2,147,483,648 to 2,147,483,647.

It is the preferred data type when we create variables with a numeric value.

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

long

A

8 bytes / 64 bits

can only store whole numbers

from
-9(Quintillion),223(Quadrillion),372(Trillion),036(Billion),854,775,808 to 9223372036854775807.
This is used when int is not large enough to store the value. Note that you should end the value with an “L”:

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

float

A

signed 4 bytes / 32 bits
Stores fractional numbers.
Sufficient for storing 6 to 7 decimal digits

The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you should end the value with an “F”:

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

double

A

signed 8 bytes / 64 bits
Stores fractional numbers.
Sufficient for storing 15 decimal digits

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

bool

A

1 bit Stores true or false values

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

char

A

2 bytes / 16 bits

Stores a single character/letter, surrounded by single quotes

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

string

A

2 bytes / 16 bits per character Stores a sequence of characters, surrounded by double quotes

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

decimal

A

signed 16 bytes / 128 bits
Stores a fractional number
up to 28-29 digits
Should end in M - decimal price = 1.50M;

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

To minimize the amount of storage used on the hard drive by an application that generates many small files, you should make the ______ as small as possible.

a - partition
b - file allocation table
c - block size
d - folder and file names

A

block size

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

byte

A

unsigned 8 BIT / 1 byte

0 to 255

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

Define Integer type (Integral)

A

Numbers that are whole numbers without decimal points. It can be negative or positive numbers.

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

Define Floating-point type

A

Floating-point type is numbers with one or more decimal points. It can be negative or positive numbers.

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

sbyte

A

signed 8 BIT / 1 byte

-128 to 127

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

short

A

It occupies 2 bytes / 16-bit memory.

The short data type is a signed integer that can store numbers from -32,768 to 32,767.

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

Signed vs unsigned values

A

signed means specified as positive or negative, unsigned means positive by default

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

Converting a value type to a reference type in an object is called BOXING.

Select the correct answer if the text in italics does not make the statement correct.

a - no change
b - unboxing
c - upcasting
d - downcasting

A

A - No change

changing a value type to a reference type = boxing

17
Q

Value Type

A

A variable of a value type contains an instance of the type.

It is stored in the stack with both its name and value in the same entry.

18
Q

Reference Type

A

contains a reference to an instance of the type (in heap memory)

An example is a string. The NAME of the variable is stored in the stack, which points to its memory address in the heap.

19
Q

Upcasting

A

Upcasting is an operation that creates a base class reference from a subclass reference. (subclass -> superclass)

(i.e. Manager -> Employee)

Example:

Employee emp = (Employee)mgr; //mgr is Manager

20
Q

Downcasting

A

Downcasting is an operation that creates a subclass reference from a base class reference. (superclass -> subclass) (i.e. Employee -> Manager)

Example:

if (employee is Manager)
{
Manager m = (Manager)employee;
}

21
Q

GUID

A

Represents a globally unique identifier (GUID). A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.

22
Q

for loop

A

When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop.

for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}

Statement 1 sets a variable before the loop starts (int i = 0).

Statement 2 defines the condition for the loop to run (i must be less than 5). If the condition is true, the loop will start over again, if it is false, the loop will end.

Statement 3 increases a value (i++) each time the code block in the loop has been executed.

23
Q

foreach loop

A

used exclusively to loop through elements in an array:

string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
foreach (string i in cars) 
{
  Console.WriteLine(i);
}
24
Q

while loop

A

The while loop loops through a block of code as long as a specified condition is True

int i = 0;
while (i < 5) 
{
  Console.WriteLine(i);
  i++;
}
25
Q

The do/while loop

A

The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.

int i = 0;
do 
{
  Console.WriteLine(i);
  i++;
}
while (i < 5);
26
Q

Which statements can you use to exit a while, do, for or foreach loop?

  • break
  • continue
  • goto
  • throw
  • reurn
A
  • break
  • goto
  • throw
  • reurn
27
Q

Break statement:

A

At any point within the while, do, for or foreach statement blocks, you can break out of the loop by using the break statement.

28
Q

Continue statement:

A

You can step directly to the evaluation of the while, do, for or foreach expression by using the continue statement.
If the expression evaluates to true, execution continues at the first statement in the loop. Otherwise, execution continues at the first statement after the loop.

29
Q

The goto statement

A

The goto statement transfers the program control directly to a labeled statement.

A common use of goto is to transfer control to a specific switch-case label or the default label in a switch statement.

The goto statement is also useful to get out of deeply nested loops.

class SwitchTest
{
    static void Main()
    {
        Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large");
        Console.Write("Please enter your selection: ");
        string s = Console.ReadLine();
        int n = int.Parse(s);
        int cost = 0;
        switch (n)
        {
            case 1:
                cost += 25;
                break;
            case 2:
                cost += 25;
                goto case 1;
            case 3:
                cost += 50;
                goto case 1;
            default:
                Console.WriteLine("Invalid selection.");
                break;
        }
        if (cost != 0)
        {
            Console.WriteLine($"Please insert {cost} cents.");
        }
        Console.WriteLine("Thank you for your business.");
    // Keep the console open in debug mode.
    Console.WriteLine("Press any key to exit.");
    Console.ReadKey();
} }
30
Q

The return statement

A

The return statement terminates execution of the method in which it appears and returns control to the calling method. It can also return an optional value. If the method is a void type, the return statement can be omitted.

If the return statement is inside a try block, the finally block, if one exists, will be executed before control returns to the calling method.

class ReturnTest
{
    static double CalculateArea(int r)
    {
        double area = r * r * Math.PI;
        return area;
    }
...
31
Q

The Throw Statement

A

Signals the occurrence of an exception during program execution.

throw [e];

32
Q

What is the purpose of a finally block in exception handling? Select all that apply.

  • execute clean up code and release resources.
  • execute code only when an exception is thrown
  • Code in a finally block is executed even if an exception is not thrown
  • to conclude the execution of an application
  • to break out of the error handler
A
  • execute clean up code and release resources.

- Code in a finally block is executed even if an exception is not thrown

33
Q

What is the purpose of the throw keyword? Select all that apply:

  • To move error handling to a separate thread
  • To stop the processing of code
  • To raise exceptions
  • To re-throw exceptions as a different type
A
  • to raise exceptions

- to re-throw exceptions as a different type