Zum Inhalt springen
Prüfung 10 Fragen

Variables and Data Types

Fragen 10

Die Lösungen sehen angemeldete Lehrkräfte.

  1. Multiple ChoiceProgramming languagesc#data typesinteger typeprimitive types

    Integer data type

    Which C# data type is used to store a whole number value such as 42 in a 32-bit signed integer?

    1. int

    2. float

    3. char

    4. bool


    Think about the keyword used for whole numbers without a decimal point.
  2. Multiple ChoiceProgramming languagesc#variable declarationSyntaxassignment

    Declaring and assigning a variable

    Which statement correctly declares an integer variable named count and assigns it the value 10?

    1. int count = 10;

    2. count int = 10;

    3. var 10 = count;

    4. int count == 10;


    A declaration gives the type first, then the name, and assignment uses a single equals sign.
  3. Multiple ChoiceProgramming languagesc#integer divisionoperatorsdata types

    Integer division

    What is the value of the expression \(7 / 2\) when both operands are int in C#?

    1. 3

    2. 3.5

    3. 3.0

    4. 4


    When both operands are integers, the result of division is also an integer and any fractional part is discarded.
  4. Multiple ChoiceProgramming languagesc#arithmetic operatorsinteger divisionmodulus operator

    Modulus operator

    What is the result of the expression 17 % 5 in C#?

    1. 2

    2. 3

    3. 3.4

    4. 5


    The percent sign gives the remainder after integer division.
  5. Multiple ChoiceProgramming languagesc#data typesfloating-point typesdouble precision

    Floating-point data type

    Which data type is most suitable in C# for storing a value with a decimal fraction such as 3.14159 with about 15 to 16 significant digits?

    1. double

    2. char

    3. string

    4. int


    Consider the floating-point type that is the default for real number literals like 3.14.
  6. Multiple ChoiceProgramming languagesc#boolean expressionslogical operatorscomparison operators

    Boolean expressions

    What value does the expression \(5 > 3 \&\& 2 == 4\) evaluate to in C#?

    1. 1

    2. false

    3. null

    4. true


    The logical AND operator returns true only when both sides are true.
  7. Multiple ChoiceProgramming languagesc#var keywordtype inferenceimplicit typing

    Implicit typing with var

    In C#, what is the inferred type of the variable total in the statement var total = 5 + 2.5;?

    1. float

    2. double

    3. decimal

    4. int


    The compiler looks at the type of the right-hand side, where an integer is combined with a double literal.
  8. Multiple ChoiceProgramming languagesc#string typevariable declarationchar type

    Character and string types

    Which declaration correctly stores the single character 'A' in C#?

    1. char letter = 'A';

    2. char letter = "A";

    3. string letter = 'A';

    4. letter char = A;


    A single character literal uses one kind of quotation mark, while a string uses another.
  9. Multiple ChoiceProgramming languagesc#type conversionexplicit castingdouble to int

    Explicit conversion

    Given double price = 9.99; what is the correct way to store its integer part in an int variable named whole?

    1. int whole = price;

    2. int whole = (int)price;

    3. int whole = int.price;

    4. int whole = Convert.ToDouble(price);


    Converting from a larger type to a smaller type requires an explicit cast in parentheses.
  10. Multiple ChoiceProgramming languagesc#operator precedencearithmetic expressionsinteger variables

    Operator precedence

    What is the value of the variable result after executing int result = 2 + 3 * 4;?

    1. 20

    2. 14

    3. 24

    4. 10


    Multiplication is evaluated before addition in C#.

Info

An exam on declaring variables, basic data types, type conversion and simple programs in C#.
Zielgruppe
Weiterführende Schule · Klassenstufen 10–11
Schwierigkeit
6 von 10
Sprache
Englisch
Wer es sehen kann
Alle
Von KI ergänzt
Was mit einem Funkelsymbol markiert ist, wurde von KI hinzugefügt.
Von KI geschrieben
Claude Haiku 5.5
Erstellt

Kommentare

  1. Noch keine Kommentare.
© Alle Rechte vorbehalten