MCQs on Operators and Expressions | Lua

1. Arithmetic Operators

  1. What does the + operator do in Lua?
    • a) Concatenates strings
    • b) Adds two numbers
    • c) Compares two numbers
    • d) Subtracts two numbers
  2. What will 10 % 3 return in Lua?
    • a) 1
    • b) 3
    • c) 0
    • d) 10
  3. Which operator is used for exponentiation in Lua?
    • a) **
    • b) ^
    • c) ^^
    • d) exp()
  4. What is the result of 15 // 4 in Lua?
    • a) 3.75
    • b) 4
    • c) 3
    • d) 15
  5. Which of these is NOT a valid arithmetic operator in Lua?
    • a) +
    • b) -
    • c) ++
    • d) %
  6. What does -a represent in Lua?
    • a) Negation of a
    • b) Absolute value of a
    • c) Positive a
    • d) Logical NOT
  7. What will 5 + 2 * 3 return in Lua?
    • a) 21
    • b) 11
    • c) 15
    • d) 7
  8. Can arithmetic operators be used on strings in Lua?
    • a) No, it causes an error
    • b) Yes, Lua converts strings to numbers
    • c) Only with concatenation
    • d) Only if strings are numerical

2. Relational Operators

  1. Which operator checks equality in Lua?
    • a) =
    • b) ==
    • c) ===
    • d) isEqual()
  2. What does a ~= b mean in Lua?
    • a) a is greater than b
    • b) a is not equal to b
    • c) a is less than or equal to b
    • d) Logical NOT of a and b
  3. Which relational operator checks if one value is greater than another?
    • a) >
    • b) <
    • c) >=
    • d) <=
  4. What does false == nil return in Lua?
    • a) true
    • b) false
    • c) nil
    • d) Error
  5. Can relational operators compare strings in Lua?
    • a) Yes, based on lexicographic order
    • b) No, it causes an error
    • c) Only with numeric strings
    • d) Only with ==
  6. What is the result of "apple" < "banana" in Lua?
    • a) true
    • b) false
    • c) Error
    • d) nil
  7. What does the <= operator signify?
    • a) Less than or equal to
    • b) Greater than or equal to
    • c) Logical AND
    • d) Logical OR

3. Logical Operators

  1. What does the and operator do in Lua?
    • a) Performs bitwise AND
    • b) Returns true only if both operands are true
    • c) Returns the negation of operands
    • d) Combines strings
  2. What is the result of true and false in Lua?
    • a) true
    • b) false
    • c) nil
    • d) Error
  3. What is the difference between or and and operators?
    • a) or requires both conditions to be true
    • b) or returns true if either condition is true
    • c) and works only on numbers
    • d) Both are equivalent
  4. What is the output of not true in Lua?
    • a) true
    • b) false
    • c) nil
    • d) Error
  5. Logical operators in Lua treat nil as:
    • a) true
    • b) false
    • c) Error-prone
    • d) Undefined

4. Concatenation Operator (..)

  1. Which operator is used to concatenate strings in Lua?
    • a) +
    • b) ..
    • c) &
    • d) concat()
  2. What is the output of "Lua" .. " Programming"?
    • a) Lua Programming
    • b) LuaProgramming
    • c) Lua+Programming
    • d) Error
  3. Can you concatenate numbers and strings directly using ..?
    • a) No, it causes an error
    • b) Yes, Lua converts numbers to strings
    • c) Only with explicit conversion
    • d) Only with formatted strings
  4. What will "Lua" .. nil output?
    • a) Lua nil
    • b) Lua
    • c) Error
    • d) nil
  5. How do you add a space while concatenating strings?
    • a) "A" .. " " .. "B"
    • b) "A" + " " + "B"
    • c) "A B"
    • d) "A & B"

5. Operator Precedence and Associativity

  1. Which operator has the highest precedence in Lua?
    • a) ^
    • b) *
    • c) +
    • d) and
  2. What is the associativity of the concatenation operator (..)?
    • a) Left-to-right
    • b) Right-to-left
    • c) No associativity
    • d) Error
  3. Which operator has the lowest precedence in Lua?
    • a) or
    • b) and
    • c) +
    • d) ^
  4. How is a + b * c evaluated in Lua?
    • a) (a + b) * c
    • b) a + (b * c)
    • c) a + b + c
    • d) a * (b + c)
  5. What is the precedence order of Lua operators?
    • a) Arithmetic > Relational > Logical
    • b) Logical > Arithmetic > Relational
    • c) Relational > Logical > Arithmetic
    • d) Logical > Relational > Arithmetic

Answers

QnoAnswer
1b) Adds two numbers
2a) 1
3b) ^
4c) 3
5c) ++
6a) Negation of a
7b) 11
8b) Yes, Lua converts strings to numbers
9b) ==
10b) a is not equal to b
11a) >
12b) false
13a) Yes, based on lexicographic order
14a) true
15a) Less than or equal to
16b) Returns true only if both operands are true
17b) false
18b) or returns true if either condition is true
19b) false
20b) false
21b) ..
22b) LuaProgramming
23b) Yes, Lua converts numbers to strings
24c) Error
25a) "A" .. " " .. "B"
26a) ^
27b) Right-to-left
28a) or
29b) a + (b * c)
30a) Arithmetic > Relational > Logical

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top