c++ programming questions

interview question in c++
1. What is the size of wchar_t in C++?
a) 2
b) 4
c) 2 or 4
d) based on the number of bits in the system
View Answer

Answer:d
Explanation: Compiler wants to make CPU as more efficient in accessing the next value

  1. What does a escape code represent?
    a) alert
    b) backslash
    c) tab
    d) form feed
    View Answer

Answer:a
Explanation: Because a is used to produce a beep sound.

  1. When a language has the capability to produce new data type mean, it can be called as
    a) overloaded
    b) extensible
    c) encapsulated
    d) reprehensible
    View Answer

Answer:b
Explanation: Extensible is used to add new features to C++.

  1. Pick the odd one out.
    a) integer, character, boolean, floating
    b) enumeration, classes
    c) integer, enum, void
    d) arrays, pointer, classes
    View Answer

Answer:c
Explanation: Option a consists of all fundamental types, option b consists of user-definied types and option d consists of derived types but option c is a mixture.

  1. Find the odd one out:
    a) std::vector
    b) std::vector
    c) std::vector
    d) std::vector
    View Answer

Answer:d
Explanation: std::vector is a specialized version of vector, which is used for elements of type bool and optimizes for space. It behaves like the unspecialized version of vector and the storage is not necessarily an array of bool values, but the library implementation may optimize storage so that each value is stored in a single bit.

  1. Which of the two operators ++ and — work for the bool datatype in C++?
    a) None
    b) ++
    c) —
    d) Both
    View Answer

Answer:b
Explanation: Due to history of using integer values as booleans, if an integer is used as a boolean, then incrementing will mean that whatever its truth value before the operation, it will have a truth-value of true after it. However, it’s not possible to predict the result of — given knowledge only of the truth value of x, as it could result in false.

  1. How do we represent a wide character of the form wchar_t?
    a) L’a’
    b) l’a’
    c) L[a] d) la
    View Answer

Answer:a
Explanation: A wide character is always indicated by immediately preceding the character literal by an L.

  1. In C++, what is the sign of character data type by default?
    a) Signed
    b) Unsigned
    c) Implementation dependent
    d) None of these
    View Answer

Answer:c
Explanation: The standard does not specify if plain char is signed or unsigned. There are three distinct character types according to the standard: char, signed char and unsigned char.

  1. Is the size of character literals different in C and C++?
    a) Implementation defined
    b) Can’t say
    c) Yes, they are different
    d) No, they are not different
    View Answer

Answer:c
Explanation: In C++, sizeof(‘a’) == sizeof(char) == 1. In C however, sizeof(‘a’) == sizeof(int).

  1. Suppose in a hypothetical machine, the size of char is 32 bits. What would sizeof(char) return?
    a) 4
    b) 1
    c) Implementation dependent
    d) Machine dependent
    View Answer

Answer:b
Explanation: The standard does NOT require a char to be 8-bits, but does require that sizeof(char) return 1.

  1. What constant defined in header returns the number of bits in a char?
    a) CHAR_SIZE
    b) SIZE_CHAR
    c) BIT_CHAR
    d) CHAR_BIT
    View Answer

Answer:d
Explanation: None.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章