C++ Set 2 (30 mcqs)

1. Choose the correct option.
extern int i;
int i;
a) both 1 and 2 declare i
b) 1 declares the variable i and 2 defines i
c) 1 declares and defines i, 2 declares i
d) 1 declares i,2 declares and defines i

2. Pick the right option
Statement 1:A definition is also a declaration.
Statement 2:An identifier can be declared just once.
a) Statement 1 is true, Statement 2 is false.
b) Statement 2 is true, Statement 1 is false.
c) Both are false.
d) Both are true.

3. Which of the given statements are false.
1. extern int func;
2. extern int func2(int,int);
3. int func2(int,int);
4. extern class foo;
a) 3 and 4 only
b) 2 and 3 only
c) only 4
d) 2, 3 and 4

4. Pick the right option
Statement 1:Global values are not initialized by the stream.
Statement 2:Local values are implicitly initialised to 0.
a) Statement 1 is true, Statement 2 is false.
b) Statement 2 is true, Statement 1 is false.
c) Both are false.
d) Both are true.

5. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int g = 100;
4.int main()
5.{
6.    int a;
7.    {
8.        int b;
9.        b = 20;
10.        a = 35;
11.        g = 65;
12.       cout << b << a << g;
13.    }
14.    a = 50;
15.    cout << a << g;
16.    return 0;
17.}
a) 2035655065
b) 2035655035
c) 2035635065
d) none of the mentioned

6. Can two functions declare variables(non static) with the same name.
a) No
b) Yes
c) Yes, but not a very efficient way to write programs.
d) No, it gives a runtime error.

7. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.void addprint()
4.{
5.    static int s = 1;
6.    s++;
7.    cout << s;
8.}
9.int main()
10.{
11.    addprint();
12.    addprint();
13.    addprint();
14.    return 0;
15.}
a) 234
b) 111
c) 123
d) 235

8. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    int a = 10;
6.    if (a < 10) {
7.        for (i = 0; i < 10; i++)
8.           cout << i;
9.    }
10.    else {
11.        cout << i;
12.    }
13.    return 0;
14.}
a) 0123456789
b) 123456789
c) 0
d) error

9. Identify the incorrect statements.
int var = 10;
int *ptr = &(var + 1); //statement 1
int *ptr2 = &var; //statement 2
&var = 40; //statement 3
a) Statement 1 and 2 are wrong
b) Statement 2 and 3 are wrong
c) Statement 1 and 3 are wrong
d) All the three are wrong

10. Identify the type of the variables.
typedef char* CHAR;
CHAR p,q;
a) char*
b) char
c) CHAR
d) unknown

11. Which operator is having right to left associativity in the following?
a) Array subscripting
b) Function call
c) Addition and subtraction
d) Type cast

12. Which operator is having the highest precedence?
a) postfix
b) unary
c) shift
d) equality

13. What is this operator called ?: ?
a) conditional
b) relational
c) casting operator
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 a;
6.    a = 5 + 3 * 5;
7.    cout << a;
8.    return 0;
9.}
a) 35
b) 20
c) 25
d) 30

15. What is the use of dynamic_cast operator?
a) it converts virtual base class to derived class
b) it converts virtual base object to derived objeccts
c) it will convert the operator based on precedence
d) None of the mentioned

16. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    int a = 5, b = 6, c, d;
6.    c = a, b;
7.    d = (a, b);
8.    cout << c << ‘t’ << d;
9.    return 0;
10.}
a) 5 6
b) 6 5
c) 6 7
d) none of the mentioned

17. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    int i, j;
6.    j = 10;
7.    i = (j++, j + 100, 999 + j);
8.    cout << i;
9.    return 0;
10.}
a) 1000
b) 11
c) 1010
d) 1001

18. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main ()
4.{
5.    int x, y;
6.    x = 5;
7.    y = ++x * ++x;
8.    cout << x << y;
9.    x = 5;
10.    y = x++ * ++x;
11.    cout << x << y;
12.    return 0;
13.}
a) 749736
b) 736749
c) 367497
d) none of the mentioned

19. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.int main()
4.{
5.    int a = 5, b = 6, c;
6.    c = (a > b) ? a : b;
7.    cout << c;
8.    return 0;
9.}
a) 6
b) 5
c) 4
d) 7

20. What is the output of this program?
1.#include <iostream>
2.using namespace std;
3.main()
4.{
5.    double a = 21.09399;
6.    float b = 10.20;
7.    int c ,d;
8.    c = (int) a;
9.    d = (int) b;
10.    cout << c <<‘t'<< d;
11.    return 0;
12.}
a) 20 10
b) 10 21
c) 21 10
d) none of the mentioned

21. Which header file is used to pass unknown number of arguments to function?
a) stdlib.h
b) string.h
c) stdarg.h
d) none of the mentioned

22. How can you access the arguments that are manipulated in the function?
a) va_list
b) arg_list
c) both a & b
d) none of the mentioned

23. What is the output of this program?
1.#include <iostream>
2.#include <stdarg.h>
3.using namespace std;
4.float avg( int Count, … )
5.{
6.    va_list Numbers;
7.    va_start(Numbers, Count);
8.    int Sum = 0;
9.    for (int i = 0; i < Count; ++i )
10.        Sum += va_arg(Numbers, int);
11.    va_end(Numbers);
12.    return (Sum/Count);
13.}
14.int main()
15.{
16.    float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
17.    cout << “Average of first 10 whole numbers : ” << Average;
18.    return 0;
19.}
a) 4
b) 5
c) 6
d) 7

24. What is the maximum number of arguments or parameters that can be
present in one function call?
a) 64
b) 256
c) 255
d) 16

25. What is the output of this program?
1.#include <iostream>
2.#include <stdarg.h>
3.using namespace std;
4.int add (int num, …)
5.{
6.    int sum = 0;
7.    va_list args;
8.    va_start (args,num);
9.    for (int i = 0; i < num; i++) {
10.        int num = va_arg (args,int);
11.        sum += num;
12.    }
13.    va_end (args);
14.    return sum;
15.}
16.int main (void)
17.{
18.    int total = add(8, 1, 2, -1, 4, 12, -2, 9, 7);
19.    cout << “The result is ” << total;
20.    return 0;
21.}
a) 32
b) 23
c) 48
d) compile time error

26. What is the output of this program?
1.#include <iostream>
2.#include <stdarg.h>
3.using namespace std;
4.void dumplist(int, …);
5.int main()
6.{
7.    dumplist(2, 4, 8);
8.    dumplist(3, 6, 9, 7);
9.    return 0;
10.}
11.void dumplist(int n, …)
12.{
13.    va_list p;
14.    int i;
15.    va_start(p, n);
16.    while (n–>0) {
17.        i = va_arg(p, int);
18.        cout << i;
19.    }
20.    va_end(p);
21.}
a) 2436
b) 48697
c) 1111111
d) compile time error

27. What is the output of this program?
1.#include <iostream>
2.#include <stdarg.h>
3.using namespace std;
4.int flue(char c,…);
5.int main()
6.{
7.    int x, y;
8.    x = flue(‘A’, 1, 2, 3);
9.    y = flue(‘1’, 1.0,1, ‘1’, 1.0f, 1l);
10.    cout << x << y;
11.    return 0;
12.}
13.int flue(char c,…)
14.{
15.    return c;
16.}
a) 6549
b) 4965
c) 6646
d) compile time error

28. Which header file should you include if you are to develop a function that can accept variablenumber of arguments?
a)varag.h
b)stdlib.h
c)stdio.h
d)stdarg.h

29. What is the output of this program?
1.#include <iostream>
2.#include <stdarg.h>
3.using namespace std;
4.void fun(std::string msg, …);
5.int main()
6.{
7.    fun(“IndiaBIX”, 1, 4, 7, 11, 0);
8.    return 0;
9.}
10.void fun(std::string msg, …)
11.{
12.    va_list ptr;
13.    int num;
14.    va_start(ptr, msg);
15.    num = va_arg(ptr, int);
16.    num = va_arg(ptr, int);
17.    cout << num;
18.}
a) 6
b) 5
c) 8
d) 4

30. What will initialize the list of arguments in stdarg.h header file?
a) va_list
b) va_start
c) va_arg
d) none of the mentioned

Answers

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

Leave a Comment

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