C++ Set 1 (28 mcqs)

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

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

3. Pick out the correct syntax of the header file that can be used with C++.
a) #include
b) #include
c) Both a & b
d) None of the mentioned

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

5. How does the limits.h header file can be represented in C++?
a) limits
b) limit
c) climits
d) None of the mentioned

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)

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

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

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

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

11. The constants are also called as
a) const
b) preprocessor
c) literals
d) none of the mentioned

12. What are the parts of the literal constants?
a) integer numerals
b) floating-point numerals
c) strings and boolean values
d) all of the mentioned

13. How the constants are declared?
a) const keyword
b) #define preprocessor
c) both a and b
d) None of the mentioned

14. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    int  const  p = 5;
6.    cout << ++p;
7.    return 0;
8.}
a) 5
b) 6
c) Error
d) None of the mentioned

15. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.#define PI 3.14159
4.int main ()
5.{
6.    float r = 2;
7.    float circle;
8.    circle = 2 * PI * r;
9.    cout << circle;
10.    return 0;
11.}
a) 12.566
b) 13.566
c) 10
d) compile time error

16. Which of the following statement is true about preprocessor directives?
a. These are lines read and processed by the preprocessor
b. They do not produce any code by themselves
c. These must be written on their own line
d. They end with a semicolon

17. Regarding following statement which of the statements is true?
const int a = 100;
a. Declares a variable a with 100 as its initial value
b. Declares a construction a with 100 as its initial value
c. Declares a constant a whose value will be 100
d. Constructs an integer type variable with a as identifier and 100 as value

18. The difference between x and ‘x’ is
a. The first one refers to a variable whose identifier is x and the second one refers to the character constant x
b. The first one is a character constant x and second one is the string literal x
c. Both are same
d. None of the mentioned

19. How to declare a wide character in string literal?
a) L prefix
b) l prefix
c) W prefix
d) none of the mentioned

20. Which of the following is not one of the sizes of the floating point types?
a) short float
b) float
c) long double
d) double

21. Which of the following is a valid floating point literal?
a) f287.333
b) F287.333
c) 287.e2
d) 287.3.e2

22. What is the range of the floating point numbers?
a) -3.4E+38 to +3.4E+38
b) -3.4E+38 to +3.4E+34
c) -3.4E+38 to +3.4E+36
d) -3.4E+38 to +3.4E+32

23. Which of three sizes of floating point types should be used when extended precision is required?
a) float
b) double
c) long double
d) extended float

24. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    float num1 = 1.1;
6.    double num2 = 1.1;
7.    if (num1 == num2)
8.       cout << “stanford”;
9.    else
10.       cout << “harvard”;
11.    return 0;
12.}
a) harvard
b) stanford
c) compile time error
d) runtime error

25. What is the output of this program?
1.#include <iomanip>
2.#include <iostream>
3.using namespace std;
4.int main()
5.{
6.    cout << setprecision(17);
7.    double d = 0.1;
8.    cout << d << endl;
9.    return 0;
10.}
a) 0.11
b) 0.10000000000000001
c) 0.100001
d) compile time error

26. What is the output of the following program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    float i = 123.0f;
6.    cout << i << endl;
7.    return 0;
8.}
a) 123.00
b) 1.23
c) 123
d) compile time error

27. Which is used to indicate single precision value?
a) F or f
b) L or l
c) either a or b
d) neither a or b

28. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    float f1 = 0.5;
6.    double f2 = 0.5;
7.    if (f1 == 0.5f)
8.        cout << “equal”;
9.    else
10.        cout << “not equal”;
11.    return 0;
12.}
a) equal
b) not equal
c) compile time error
d) runtime error

Answers

1-c 2-a 3-b 4-d 5-c
6-c 7-d 8-a 9-b 10-c
11-c 12-d 13-c 14-c 15-a
16-d 17-c 18-c 19-a 20-a
21-c 22-a 23-c 24-a 25-b
26-c 27-a 28-a

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

shares