1/25
Comprehensive practice flashcards covering variables, data types, operator precedence, integer division, string concatenation, casting, compound assignment, and Unity public fields.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is a variable in C#?
A named place to keep a value of a declared type.
What are the five components that make up the anatomy of a variable declaration and initialization in C#?
Type, name, equals sign, value, semicolon.
What is the difference between variable declaration, initialization, and assignment?
Declaration creates a variable with a type and name. Initialization gives it a first value. Assignment stores a new value later, replacing the old value.
What is the camelCase naming convention in C#?
A naming style where the first word is lowercase and each subsequent word is capitalized, such as jumpCount.
What are the rules for identifier names in C#?
Identifiers may use letters, digits, and underscores, but they cannot start with a digit.
What are the four basic C# types introduced in the study guide and what values do they hold?
int holds whole numbers and counts; float holds decimals, times, and prices; string holds text in double quotes; bool holds true or false.
How must a float literal be formatted in C#?
It requires a decimal point and an f suffix, such as 3.75f.
What error is generated when trying to store a float value inside an int variable?
error CS0266: Cannot implicitly convert type 'float' to 'int'.
Why is 6,5f an invalid float literal in C#?
C# requires a decimal point (6.5f) rather than a comma.
What is the purpose of Debug.Log() in Unity C#?
It prints messages and variable values to the Unity Console.
What are the five basic arithmetic operators in C# and what does the % operator do?
The operators are +, -, *, /, and %. Modulo (%) calculates the remainder of integer division.
What is the order of operator precedence in C# arithmetic expressions?
Parentheses first, then *, /, and %, followed by + and -. Operators at the same level resolve left to right.
What is the result of evaluating the C# expression 10 - 2 * 3 + 8 / 4?
6
How does integer division work in C# when dividing two int operands?
The division truncates (throws away) the remainder, leaving only the whole number.
Why do int a = 5 / 3 * 6; and int b = 5 * 6 / 3; yield different results?
Because division truncates before multiplication in line a (5 / 3 becomes 1, then 1 * 6 = 6), whereas in line b multiplication happens first (30 / 3 = 10).
How does the + operator behave when combining strings and numbers in C#?
Once a string is encountered on the left, + performs string concatenation instead of addition. If numbers come before any text, they add numerically first.
What output is produced by Debug.Log("Score: " + 4 + 5);?
Score: 45
What output is produced by Debug.Log(4 + 5 + " pts");?
9 pts
What is the difference between implicit and explicit type conversion (casting) in C#?
Implicit conversion happens automatically for safe conversions (like int to float). Explicit conversion must be written with a cast like (int) and truncates decimals without rounding.
Why does float rateLate = (float)(made / tried); result in 1 when made = 7 and tried = 4?
The cast occurs too late; integer division (7 / 4) already dropped the remainder before the result was cast to float.
What are compound assignment operators in C#?
Shorthand operators (+=, -=, *=, /=) that update a variable using its current value, such as ammo -= 4 for ammo = ammo - 4.
Where is a public field declared in a Unity script and where does it appear in the editor?
It is declared inside the class outside of Start(), and it appears as an editable field in the Unity Inspector.
In Unity, if a public field value is modified in code after the script is attached to an object, which value is used?
The Inspector value wins, so editing the default value in code will not change it on the object.
What value is stored by int leftover = 29 % 6;?
5
What value is stored by int k = (int)6.8f;?
6
What is the value of hp after running int hp = 20; hp -= 6; hp *= 2;?
28