Integer Types(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option C. -> Compiler error may be possibleUsing & on a register variable may be invalid, since the compiler may store the variable in a register, and
finding the address of it is illegal.
Question 2.
What will be output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int i = 3;
6.
int l = i / -2;
7.
int k = i % -2;
8.
cout
- compile time error
- -1 1
- 1 -1
- implementation defined
Explanation:-
Answer: Option B. -> -1 1Sign of result of mod operation on negative numbers is sign of the dividend.
Question 3.
What will be the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int a = 8;
6.
cout << "ANDing integer 'a' with 'true' :"" << a && true;
7.
return 0;
8.
}
- integer 'a' with 'true' :8
- ANDing integer 'a' with 'true' :0
- ANDing integer 'a' with 'true' :1
- None of the mentioned
Explanation:-
Answer: Option A. -> integer 'a' with 'true' :8None.
Question 4. 0946, 786427373824, 'x' and 0X2f are _____, _____, ____ and _____ literals respectively
- decimal, character,octal, hexadecimal
- octal, hexadecimal, character, decimal
- hexadecimal, octal, decimal, character
- octal, decimal, character, hexadecimal
Explanation:-
Answer: Option D. -> octal, decimal, character, hexadecimalLiteral integer constants that begin with 0x or 0X are interpreted as hexadecimal and the ones that begin
with 0 as octal. The character literal are written within ".
Explanation:-
Answer: Option C. -> x = x & (-x)None.
Explanation:-
Answer: Option B. -> x = x & (x-1)None.
Explanation:-
Answer: Option D. -> (v & (v - 1)) == 0;Power of two integers have a single set bit followed by unset bits.
Explanation:-
Answer: Option D. -> Implementation defined Right shift of signed integers is undefined, and has implementation-defined behaviour.
Explanation:-
Answer: Option C. -> Unsigned integer of at least 16 bitsThe size_t type is used to represent the size of an object. Hence, it’s always unsigned. According to
the language specification, it is at least 16 bits.
Question 10.
What is the output of the following program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int x = -1;
6.
unsigned int y = 2;
7.
8.
if(x > y) {
9.
cout
- x is greater
- y is greater
- Implementation defined
- Arbitrary
Explanation:-
Answer: Option A. -> x is greaterx is promoted to unsigned int on comparison. On conversion x has all bits set, making it the bigger one.