C# משתנים ותנאים
שאלות 10
מפתח התשובות מוצג למורים מחוברים.
-
-
-
Tracing an if / else if Chain
What is printed by the following code?
int a = 5;
int b = 10;
if (a > 3 && b < 5)
Console.WriteLine("X");
else if (a == 5)
Console.WriteLine("Y");
else
Console.WriteLine("Z");X
Nothing is printed
Y
Z
Evaluate the first condition carefully: both parts of the && must be true. If it fails, move to the else if. -
-
Unassigned Local Variable
What happens when the following code is compiled and run?
int total;
Console.WriteLine(total);It prints 0
A runtime NullReferenceException is thrown
A compile-time error occurs because total is used before it is assigned a value
It prints an empty line
Local variables in C# must be definitely assigned before they are read. The compiler checks this before the program runs. -
-
-
-
Conditions in if statements
Given int x; the statement if (x = 5) Console.WriteLine("Five"); compiles without errors in C#, because the assignment is accepted as the condition.
True
False
Consider what type of value an if statement requires for its condition, and what type the assignment expression produces. -
Value types and reference types
In C#, the string type is a value type, so a copy of a string variable holds its own separate copy of the characters.
True
False
Recall the difference between value types, which store their data directly, and reference types, which store a reference to an object on the heap.
פרטים
- מקצועות
- c#
- קהל יעד
- תיכון · כיתות י׳–י״א
- רמת קושי
- 6 מתוך 10
- שפה
- אנגלית
- מי יכול לראות
- כולם
- נוצר באמצעות AI
- Claude Haiku 5.5
- נוצר
תגובות