Data Types MCQs

100 MCQs  (Page 8 of 10)

In C++, what is the difference between const int *p and int * const p?
The first is a pointer to const int (the data cannot change); the second is a const pointer (it cannot be redirected)
The first is a const pointer; the second is a pointer to const
They are identical
Both prevent all modification
Which statement about C++ references is correct?
A reference can be reassigned to another variable
A reference can be null
A reference must be initialized and cannot be reseated to refer to another object
A reference always occupies more memory than a pointer
Why can't a void* be dereferenced directly in C++?
Its pointed-to type is unknown, so it must first be cast to a typed pointer
It is read-only
It is 0 bytes in size
It always points to NULL
What is the main advantage of nullptr (C++11) over NULL?
It frees memory automatically
It can be dereferenced safely
It is faster
It has its own type (std::nullptr_t) and is never mistaken for an integer during overload resolution
What is the size of a union?
Always 8 bytes
At least the size of its largest member (plus any alignment padding), because all members share the same memory
The size of its first member
The sum of all its members' sizes
What is the main advantage of a C++11 enum class over a plain enum?
It uses less memory
It allows floating-point values
Its values can be strings
Its enumerators are scoped and do not implicitly convert to int
Given t = ([1],), what happens with t[0].append(2)?
It succeeds and t becomes ([1, 2],)
AttributeError
t becomes ([1], 2)
TypeError, because tuples are immutable