C++ quiz questions

C++ interview questions

  • 1.

    The data elements in structure are also known as what?

    1. objects

    2. members

    3. datas

    4. none of the mentioned

    Answer
  • 2.

    What we can’t do on a void pointer?

    1. pointer arithemetic

    2. pointer functions

    3. both of the mentioned

    4. none of the mentioned

    Answer
  • 3.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int a = 5, c;
            void *p = &a;
            double b = 3.14;
            p = &b;
            c = a + b;
            cout << c << '\n' << p;
            return 0;
        }

     

    1. 8, memory address

    2. 8.14

    3. memory address

    4. none of the mentioned

    Answer
  • 4.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int n = 5;
            void *p = &n;
            int *pi = static_cast<int*>(p);
            cout << *pi << endl;
            return 0;
        }

     

    1. 5

    2. 6

    3. compile time error

    4. runtime error

    Answer
  • 5.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int i;
            char c;
            void *data;
            i = 2;
            c = 'd';
            data = &i;
            cout << "the data points to the integer value" << data;
            data = &c;
            cout << "the data now points to the character" << data;
            return 0;
        }

     

    1. 2d

    2. two memory addresses

    3. both of the mentioned

    4. none of the mentioned

    Answer
  • 6.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int *p;
            void *vp;
            if (vp == p);
                cout << "equal";
            return 0;
        }

     

    1. equal

    2. no output

    3. compile error

    4. runtime error

    Answer
  • 7.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int func(void *Ptr);
        int main()
        {
            char *Str = "abcdefghij";
            func(Str);
            return 0;
        }
        int func(void *Ptr)
        {
            cout << Ptr;
            return 0;
        }

     

    1. abcdefghij

    2. address of string “abcdefghij”

    3. compile time error

    4. runtime error

    Answer
  • 8.

    A void pointer cannot point to which of these?

    1. methods in c++

    2. class member in c++

    3. all of the mentioned

    4. none of the mentioned

    Answer
  • 9.

    The pointer can point to any variable that is not declared with which of these?

    1. const

    2. volatile

    3. both a & b

    4. static

    Answer
  • 10.

    When does the void pointer can be dereferenced?

    1. when it doesn’t point to any value

    2. when it cast to another type of object

    3. using delete keyword

    4. none of the mentioned

    Answer
  • 11.

    Void pointer can point to which type of objects?

    1. int

    2. float

    3. double

    4. all of the mentioned

    Answer
  • 12.

    Identify the correct sentence regarding inequality between reference and pointer.

    1. we can not create the array of reference.

    2. we can create the Array of reference.

    3. we can use reference to reference.

    4. none of the mentioned

    Answer
  • 13.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        void print (char * a)
        {
            cout << a << endl;
        }
        int main ()
        {
            const char * a = "Hello world";
            print(const_cast<char *> (a) );
            return 0;
        }

     

    1. Hello world

    2. Hello

    3. world

    4. compile time error

    Answer
  • 14.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int a = 9;
            int & aref = a;
            a++;
            cout << "The value of a is " << aref;
            return 0;
        }

     

    1. 9

    2. 10

    3. error

    4. 11

    Answer
  • 15.

    What does a reference provide?

    1. Alternate name for the class

    2. Alternate name for the variable

    3. Alternate name for the pointer

    4. none of the mentioned

    Answer
  • 16.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        void swap(int &a, int &b);
        int main()
        {
            int a = 5, b = 10;
            swap(a, b);
            cout << "In main " << a << b;
            return 0;
        }
        void swap(int &a, int &b)
        {
            int temp;
            temp = a;
            a = b;
            b = temp;
            cout << "In swap " << a << b;
        }

     

    1. In swap 105 In main 105

    2. In swap 105 In main 510

    3. In swap 510 In main 105

    4. none of the mentioned

    Answer
  • 17.

    Which reference modifier is used to define reference variable?

    1. &

    2. $

    3. #

    4. none of the mentioned

    Answer
  • 18.

    Identify the incorrect statement

    1. reference is the alternate name of the object

    2. A reference value once defined can be reassigned

    3. A reference value once defined cannot be reassigned

    4. none of the mentioned

    Answer
  • 19.

    Which value we cannot assign to reference?

    1. integer

    2. floating

    3. unsigned

    4. null

    Answer
  • 20.

    How to declare a wide character in string literal?

    1. L prefix

    2. l prefix

    3. W prefix

    4. none of the mentioned

    Answer

© 2017 QuizBucket.org