C++ quiz questions

C++ interview questions

  • 1.

    Can two functions declare variables(non static) with the same name.

    1. No

    2. Yes

    3. Yes, but not a very efficient way to write programs.

    4. No, it gives a runtime error.

    Answer
  • 2.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int g = 100;
        int main()
        {
            int a;
            {
                int b;
                b = 20;
                a = 35;
                g = 65;
               cout << b << a << g;
            }
            a = 50;
            cout << a << g;
            return 0;
        }

     

    1. 2035655065

    2. 2035655035

    3. 2035635065

    4. none of the mentioned

    Answer
  • 3.

    Pick the right option

        Statement 1:Global values are not initialized by the stream.
        Statement 2:Local values are implicitly initialised to 0.

    1. Statement 1 is true, Statement 2 is false.

    2. Statement 2 is true, Statement 1 is false.

    3. Both are false.

    4. Both are true.

    Answer
  • 4.

    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;

    1. 3 and 4 only

    2. 2 and 3 only

    3. only 4

    4. 2, 3 and 4

    Answer
  • 5.

    Pick the right option

        Statement 1:A definition is also a declaration.
        Statement 2:An identifier can be declared just once.

    1. Statement 1 is true, Statement 2 is false.

    2. Statement 2 is true, Statement 1 is false.

    3. Both are false.

    4. Both are true.

    Answer
  • 6.

    Choose the correct option.

        extern int i;
        int i;

    1. both 1 and 2 declare i

    2. 1 declares the variable i and 2 defines i

    3. 1 declares and defines i, 2 declares i

    4. 1 declares i,2 declares and defines i

    Answer
  • 7.

    What is output of the this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int i;
            enum month {
                JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC
            };
            for (i = MAR; i <= NOV; i++)
                cout << i;
            return 0;
        }

     

    1. 01234567891011

    2. 123456789101112

    3. 34567891011

    4. 123456789

    Answer
  • 8.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            enum channel {star, sony, zee};
            enum symbol {hash, star};
            int i = 0;
            for (i = star; i <= zee; i++) {
                printf("%d ", i);
            }
            return 0;
        }

     

    1. 012

    2. 123

    3. compile time error

    4. runtime error

    Answer
  • 9.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        enum colour {
            green, red, blue, white, yellow, pink
        };
        int main()
        {
            cout << green<< red<< blue<< white<< yellow<< pink;
            return 0;
        }

     

    1. 012345

    2. 123456

    3. compile time error

    4. runtime error

    Answer
  • 10.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        enum test {
            A = 32, B, C
        };
        int main()
        {
            cout << A << B<< C;
            return 0;
        }

     

    1. 323334

    2. 323232

    3. 323130

    4. none of the mentioned

    Answer
  • 11.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        enum  cat {
            temp = 7
        };
        int main()
        {
            int age = 14;
            age /= temp;
            cout << "If you were cat, you would be " << age << endl;
            return 0;
        }

     

    1. If you were cat, you would be 5

    2. If you were cat, you would be 2

    3. If you were cat, you would be 7

    4. none of the mentioned

    Answer
  • 12.

    Which variable does equals in size with enum variable?

    1. int variable

    2. float variable

    3. string variable

    4. none of the mentioned

    Answer
  • 13.

    What will happen when defining the enumerated type?

    1. it will not allocate memory

    2. it will allocate memory

    3. it will not allocate memory to its variables

    4. none of the mentioned

    Answer
  • 14.

    To which of these enumerators can be assigned?

    1. integer

    2. negative

    3. enumerator

    4. all of the mentioned

    Answer
  • 15.

    In which type does the enumerators are stored by the compiler?

    1. string

    2. integer

    3. float

    4. none of the mentioned

    Answer
  • 16.

    Identify the incorrect option.

    1. enumerators are constants

    2. enumerators are user defined types

    3. enumerators are same as macros

    4. enumerator values start from 0 by default

    Answer
  • 17.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            void a = 10, b = 10;
            int c;
            c = a + b;
            cout << c;
            return 0;
        }

     

    1. 20

    2. compile time error

    3. runtime error

    4. none of the mentioned

    Answer
  • 18.

    Choose the incorrect option

    1. void is used when the function does not return a value.

    2. void is also used when the value of a pointer is null.

    3. void is used as the base type for pointers to objects of unknown type.

    4. void is a special fundamental type.

    Answer
  • 19.

    What does the following statement mean?

    void a;

    1. variable a is of type void

    2. a is an object of type void

    3. declares a variable with value a

    4. flags an error

    Answer
  • 20.

    ____ have the return type void?

    1. all functions

    2. constructors

    3. destructors

    4. none of the mentioned

    Answer

© 2017 QuizBucket.org