التخطي إلى المحتوى
اختبار 10 أسئلة

Variables and Data Types

الأسئلة 10

يظهر مفتاح الإجابات للمعلمين المسجَّلين الدخول.

  1. اختيار من متعددProgramming languagesintdata typesIntegersvariablesprimitive types

    Integer Storage

    Which data type is most appropriate for storing the number of students in a class, such as 28?

    1. bool

    2. char

    3. int

    4. float


    Think about which type holds whole numbers without a fractional part.
  2. اختيار من متعددProgramming languagesbooleandata typesvariablesprimitive typeslogical values

    Boolean Values

    A program stores whether a user is logged in. Which data type is best suited for this single yes-or-no value?

    1. bool

    2. double

    3. string

    4. long


    The value can only be one of two states: true or false.
  3. اختيار من متعددProgramming languagesfloatdata typesdecimal numbersmeasurementprimitive types

    Floating-Point Precision

    Which data type should be used to store a measurement such as a temperature of 36.6 degrees?

    1. int

    2. float

    3. bool

    4. char


    Consider the type designed for numbers that include a decimal point.
  4. اختيار من متعددProgramming languagesdata typescharcharactersvariablesprimitive types

    Character Storage

    In many languages such as C and C++, which type stores a single letter like 'A'?

    1. char

    2. bool

    3. int

    4. string


    This type holds one symbol from a character set, not a whole word.
  5. اختيار من متعددProgramming languagesvariable namingidentifiersreserved words

    Variable Naming Rules

    Which of the following is a valid variable name in most programming languages?

    1. user_name

    2. total-count

    3. 2score

    4. class


    Recall the rules: names cannot start with a digit, cannot contain hyphens, and cannot be reserved keywords.
  6. اختيار من متعددProgramming languagesvariablesassignment statementsvariable values

    Assignment Behaviour

    After the statements x = 5 followed by y = x and then x = 10, what is the value of y?

    1. 10

    2. Undefined

    3. 0

    4. 5


    Assignment copies the value at the moment it happens; later changes to x do not affect y.
  7. اختيار من متعددProgramming languagesdata typesinteger overflownumber ranges

    Type Limitations

    Why might storing a very large whole number in a 32-bit int variable cause a problem?

    1. int variables can only store negative numbers

    2. The compiler deletes large values

    3. The value may exceed the range the type can represent, causing overflow

    4. int variables automatically become strings


    Every fixed-size integer type has a minimum and maximum value it can hold.
  8. صح / خطأProgramming languagesstatic typingtype checkingdata types

    Static typing and assignment

    In a statically typed language such as Java, a variable declared as int can be assigned the text value "hello" without any conversion or error.

    1. True

    2. False


    Think about what the compiler checks before the program runs, and whether the declared type must match the value stored in the variable.
  9. صح / خطأProgramming languagesdynamic typingdata typespython variables

    Dynamic typing in Python

    In Python, a variable is not bound to a fixed type at declaration, so the same variable name can first refer to an integer and later refer to a string.

    1. True

    2. False


    Consider how Python decides the type of a name: is it fixed when the variable is created, or can it refer to different kinds of objects over time?
  10. صح / خطأProgramming languagesfloating-pointbinary representationrounding errors

    Floating-point precision

    Because of how decimal numbers are stored in binary, the value of \(0.1+0.2\) computed with floating-point arithmetic in most languages is exactly equal to \(0.3\).

    1. True

    2. False


    Floating-point types store approximations of many decimal fractions. Consider whether \(0.1\) can be represented exactly in binary.

نبذة

A quiz on variables, integers, strings and booleans in programming, with questions on choosing the right type and reading simple code.
المواد
Programming languages
الفئة المستهدفة
المدرسة الثانوية · الصفوف 10–11
الصعوبة
6 من 10
اللغة
الإنجليزية
من يمكنه رؤيته
الجميع
أكمله الذكاء الاصطناعي
ما يحمل علامة البريق أضافه الذكاء الاصطناعي.
كتبه الذكاء الاصطناعي
Claude Haiku 5.5
تاريخ الإنشاء

التعليقات

  1. لا توجد تعليقات بعد.
© جميع الحقوق محفوظة