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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值