close

出題來源:http://www.lua.org/pil/

出題範圍:

Part I · The Language 

1 – Getting Started

2 – Types and Values

3 – Expressions

題型:是非題

想知道答案就直接反白吧

A.是非題

Q1: print(10 .. "" == "10") 的結果 會出錯。

X,等同 print(tostring(10) == "10") --> true,另外 .. 比 == 更優先

Q2:

--[[

XXXXXXX

]]--是多行註解,則當a=3時,---[[print(a)]]--單行註解時,不會有任何輸出。

O,因為語法一開始有問題所以後台也當作沒看到了。

Q3:

b = {}

b.x = 3

print(b[x]),結果是3。

X,結果是Nil。print(b["x"])結果才是3。

Q4:

b = {}

b[x] = 3

print(b[x]),結果是3。

X,第二行就會出錯了。因為此時X不是字串型別,而是數值型別,不可能以X=Nil做索引的。

Q5:print(nil and false) 結果是false

X,是Nil。

The operatorand returns its first argument if it is false; otherwise, it returns its second argument. The operator or returns its first argument if it is not false; otherwise, it returns its second argument

中文翻譯就是and的情況,只要第一個不是False或是Nil,它就直接回傳第二個引數;

or的情況只要第一個不是true,它就直接回傳第二個引數。

Q6:運算子優先度最高的是Not。

X,排名如下。

^ not - (unary) * / + - .. < > <= >= ~= == and or
arrow
arrow
    全站熱搜

    abcdefg 發表在 痞客邦 留言(0) 人氣()