Variables, Types & Operators - C# in Unity Study Guide

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

flashcard set

Earn XP

Description and Tags

Comprehensive practice flashcards covering variables, data types, operator precedence, integer division, string concatenation, casting, compound assignment, and Unity public fields.

Last updated 12:13 PM on 10/1/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

26 Terms

1
New cards

What is a variable in C#?

A named place to keep a value of a declared type.

2
New cards

What are the five components that make up the anatomy of a variable declaration and initialization in C#?

Type, name, equals sign, value, semicolon.

3
New cards

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.

4
New cards

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.

5
New cards

What are the rules for identifier names in C#?

Identifiers may use letters, digits, and underscores, but they cannot start with a digit.

6
New cards

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.

7
New cards

How must a float literal be formatted in C#?

It requires a decimal point and an f suffix, such as 3.75f.

8
New cards

What error is generated when trying to store a float value inside an int variable?

error CS0266: Cannot implicitly convert type 'float' to 'int'.

9
New cards

Why is 6,5f an invalid float literal in C#?

C# requires a decimal point (6.5f) rather than a comma.

10
New cards

What is the purpose of Debug.Log() in Unity C#?

It prints messages and variable values to the Unity Console.

11
New cards

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.

12
New cards

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.

13
New cards

What is the result of evaluating the C# expression 10 - 2 * 3 + 8 / 4?

6

14
New cards

How does integer division work in C# when dividing two int operands?

The division truncates (throws away) the remainder, leaving only the whole number.

15
New cards

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).

16
New cards

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.

17
New cards

What output is produced by Debug.Log("Score: " + 4 + 5);?

Score: 45

18
New cards

What output is produced by Debug.Log(4 + 5 + " pts");?

9 pts

19
New cards

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.

20
New cards

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.

21
New cards

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.

22
New cards

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.

23
New cards

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.

24
New cards

What value is stored by int leftover = 29 % 6;?

5

25
New cards

What value is stored by int k = (int)6.8f;?

6

26
New cards

What is the value of hp after running int hp = 20; hp -= 6; hp *= 2;?

28