Recall & Review
beginner
What is a variable declaration in C#?
A variable declaration tells the computer to create a space in memory to store a value of a specific type, like
int or string.Click to reveal answer
beginner
What does variable initialization mean?
Initialization means giving a variable its first value when you create it, for example:
int age = 25; sets the variable age to 25 right away.Click to reveal answer
beginner
How do you declare and initialize a string variable named
name with the value "Alice"?You write:
string name = "Alice"; This creates a variable called name that holds the text "Alice".Click to reveal answer
beginner
Can you declare a variable without initializing it? Give an example.
Yes, you can declare a variable without giving it a value immediately. For example:
int number; declares the variable but does not set its value yet.Click to reveal answer
intermediate
What happens if you try to use a variable before initializing it in C#?
C# will give an error because variables must have a value before you use them. The compiler wants to make sure you don’t use empty or unknown values.
Click to reveal answer
Which of the following is a correct variable declaration and initialization in C#?
✗ Incorrect
Option B correctly declares an integer variable named count and sets it to 10.
What type of value can a variable of type
bool hold?✗ Incorrect
A
bool variable holds only two values: true or false.What is the result of this code?<br>
int x;<br>Console.WriteLine(x);✗ Incorrect
Using an uninitialized variable
x causes a compilation error in C#.Which of the following can be used to declare a variable in C#?
✗ Incorrect
int (C) and var (D) can be used to declare variables. let (B) is not used in C#.How do you declare a variable without initializing it?
✗ Incorrect
Option D declares the variable
number without giving it a value.Explain in your own words what variable declaration and initialization mean in C#.
Think about how you tell the computer to remember something and give it a value.
You got /4 concepts.
Describe what happens if you try to use a variable before initializing it in C#.
What does the computer say if you try to use empty memory?
You got /3 concepts.