Integer Types C++ MCQ

Errorlogger
0
1. The size_t integer type in C++ is?
a) Unsigned integer of at least 64 bits
b) Signed integer of at least 16 bits
c) Unsigned integer of at least 16 bits
d) Signed integer of at least 64 bits

Answer:c


2. What is the output of the following program?
  1.     #include <iostream>
  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";
  10.     	} else {
  11.     		cout << "y is greater";
  12.     	}
  13.     }
a) x is greater
b) y is greater
c) Implementation defined
d) Arbitrary

Answer:a


3. Which of these expressions will return true if the input integer v is a power of two?
a) (v | (v + 1)) == 0;
b) (v & (v – 1)) == 0;
c) (v | (v + 1)) == 0;
d) (v & (v – 1)) == 0;

Answer:d


4. What is the value of the following 8-bit integer after all statements are executed?
int x = 1;
x = x << 7;
x = x >> 7;
a) 1
b) -1
c) 127
d) Implementation defined

Answer:d


5. Which of these expressions will make the rightmost set bit zero in an input integer x?
a) x = x | (x-1)
b) x = x & (x-1)
c) x = x | (x+1)
d) x = x & (x+1)

Answer:b


6. Which of these expressions will isolate the rightmost set bit?
a) x = x & (~x)
b) x = x ^ (~x)
c) x = x & (-x)
d) x = x ^ (-x)

Answer:c


7. 0946, 786427373824, ‘x’ and 0X2f are _____, _____, ____ and _____ literals respectively
a) decimal, character,octal, hexadecimal
b) octal, hexadecimal, character, decimal
c) hexadecimal, octal, decimal, character
d) octal, decimal, character, hexadecimal

Answer:d


8. What will be the output of this program?
  1.     #include <iostream>
  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.     }
a) ANDing integer ‘a’ with ‘true’ :8
b) ANDing integer ‘a’ with ‘true’ :0
c) ANDing integer ‘a’ with ‘true’ :1
d) None of the mentioned

Answer:a


9. What will be output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         int i = 3;
  6.         int l = i / -2;
  7.         int k = i % -2;
  8.         cout << l << k;
  9.         return 0;
  10.     }
a) compile time error
b) -1 1
c) 1 -1
d) implementation defined

Answer:b


10. What will be output of this function?
  1.     int main()
  2.     {
  3.         register int i = 1;
  4.         int *ptr = &i;
  5.         cout << *ptr;
  6. 	return 0;
  7.     }
a) 0
b) 1
c) Compiler error may be possible
d) Runtime error may be possible

Answer:c
Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !