Data Types MCQs

100 MCQs  (Page 6 of 10)

What happens with char s[5] = "hello"; in C++?
It compiles, and s has no null terminator
Compilation error (the initializer is too long)
s holds "hell"
It compiles and is null-terminated
What happens with s = "abc"; s[0] = "z" in Python?
s becomes "z"
IndexError
s becomes "zbc"
TypeError: 'str' object does not support item assignment
What is "ab" * 3 in Python?
["ab", "ab", "ab"]
"ababab"
"ab3"
TypeError
In C, given char a[] = "hi", b[] = "hi";, what does a == b evaluate to?
Undefined behavior
Compilation error
False (0), because the comparison is between the two array addresses
True (1)
What is the result of sorted(["b", "B", "a", "A"]) in Python?
['a', 'A', 'b', 'B']
['A', 'B', 'a', 'b']
['a', 'b', 'A', 'B']
['A', 'a', 'B', 'b']