דילוג לתוכן
מבחן 10 שאלות

C# משתנים ותנאים

שאלות 10

מפתח התשובות מוצג למורים מחוברים.

  1. רב־ברירהc#

    Integer Division

    What is the value of x after the following statement is executed?

    int x = 7 / 2;

    1. 3

    2. 3.5

    3. 4

    4. 3.0


    Think about what type the result of dividing two int values has in C#, and what happens to the fractional part.
  2. רב־ברירהc#

    Choosing a Data Type for Money

    Which C# data type is generally the most appropriate for storing a bank account balance, where exact decimal precision is important?

    1. char

    2. bool

    3. decimal

    4. int


    This type is designed for financial calculations and keeps decimal digits precise, unlike binary floating-point types.
  3. רב־ברירהc#

    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");

    1. X

    2. Nothing is printed

    3. Y

    4. Z


    Evaluate the first condition carefully: both parts of the && must be true. If it fails, move to the else if.
  4. רב־ברירהc#

    Char versus String Literals

    In C#, what is the data type of the literal 'A' (written with single quotation marks)?

    1. byte

    2. int

    3. char

    4. string


    Single quotation marks hold one character, while double quotation marks are used for text sequences.
  5. רב־ברירהc#

    Unassigned Local Variable

    What happens when the following code is compiled and run?

    int total;
    Console.WriteLine(total);

    1. It prints 0

    2. A runtime NullReferenceException is thrown

    3. A compile-time error occurs because total is used before it is assigned a value

    4. 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.
  6. רב־ברירהc#logical operatorsoperator precedenceboolean expressions

    Boolean Expression Evaluation

    What is printed by the following code?

    bool flag = !(3 > 2) || 4 == 4;
    Console.WriteLine(flag);

    1. True

    2. False

    3. A compile-time error occurs

    4. 1


    Evaluate 3 > 2 first, then apply the NOT operator, then the OR operator. Remember that || is true if either side is true.
  7. רב־ברירהc#explicit castingtype conversionnumeric types

    Explicit Conversion Between Numeric Types

    What is the value of i after the following code is executed?

    double d = 3.9;
    int i = (int)d;

    1. 3.9

    2. A compile-time error occurs

    3. 3

    4. 4


    Converting a double to an int with a cast discards the fractional part rather than rounding it.
  8. נכון / לא נכוןc#var keywordlocal variablestype inference

    Implicitly typed local variables

    In C#, a local variable declared with the var keyword must be given an initial value in the same declaration statement.

    1. True

    2. False


    Think about how the compiler determines the type of a var variable when it is declared.
  9. נכון / לא נכוןc#if statementassignment operatorcompile errors

    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.

    1. True

    2. False


    Consider what type of value an if statement requires for its condition, and what type the assignment expression produces.
  10. נכון / לא נכוןc#value typesreference typesstring type

    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.

    1. True

    2. 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#: הגדרת משתנים, טיפוסי נתונים, משפטי if ו-switch ותנאים מורכבים.
מקצועות
c#
קהל יעד
תיכון · כיתות י׳–י״א
רמת קושי
6 מתוך 10
שפה
אנגלית
מי יכול לראות
כולם
נוצר באמצעות AI
Claude Haiku 5.5
נוצר

תגובות

  1. אין תגובות עדיין.
© כל הזכויות שמורות