C++ quiz questions

C++ interview questions

  • 1.

    How many sequence of statements are present in c++?

    1. 4

    2. 3

    3. 5

    4. 6

    Answer
  • 2.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        main()
        {
            double a = 21.09399;
            float b = 10.20;
            int c ,d;
            c = (int) a;
            d = (int) b;
            cout << c <<' '<< d;
            return 0;
        }

     

    1. 20 10

    2. 10 21

    3. 21 10

    4. none of the mentioned

    Answer
  • 3.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int a = 5, b = 6, c;
            c = (a > b) ? a : b;
            cout << c;
            return 0;
        }

     

    1. 6

    2. 5

    3. 4

    4. 7

    Answer
  • 4.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main ()
        {
            int x, y;
            x = 5;
            y = ++x * ++x;
            cout << x << y;
            x = 5;
            y = x++ * ++x;
            cout << x << y;
            return 0;
        }

     

    1. 749736

    2. 736749

    3. 367497

    4. none of the mentioned

    Answer
  • 5.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int i, j;
            j = 10;
            i = (j++, j + 100, 999 + j);
            cout << i;
            return 0;
        }

     

    1. 1000

    2. 11

    3. 1010

    4. 1001

    Answer
  • 6.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int a = 5, b = 6, c, d;
            c = a, b;
            d = (a, b);
            cout << c << ' ' << d;
            return 0;
        }

     

    1. 5 6

    2. 6 5

    3. 6 7

    4. none of the mentioned

    Answer
  • 7.

    What is the use of dynamic_cast operator?

    1. it converts virtual base class to derived class

    2. it converts virtual base object to derived objeccts

    3. it will convert the operator based on precedence

    4. None of the mentioned

    Answer
  • 8.

    What is the output of this program?

    
        #include <iostream>
        using namespace std;
        int main()
        {
            int a;
            a = 5 + 3 * 5;
            cout << a;
            return 0;
        }

     

    1. 35

    2. 20

    3. 25

    4. 30

    Answer
  • 9.

    What is this operator called ?: ?

    1. conditional

    2. relational

    3. casting operator

    4. none of the mentioned

    Answer
  • 10.

    Which operator is having the highest precedence?

    1. postfix

    2. unary

    3. shift

    4. equality

    Answer
  • 11.

    Which operator is having right to left associativity in the following?

    1. Array subscripting

    2. Function call

    3. Addition and subtraction

    4. Type cast

    Answer
  • 12.

    Which of the following accesses a variable in structure *b?

    1. b->var;

    2. b.var;

    3. b-var;

    4. b>var;

    Answer
  • 13.

    Which of the following is a properly defined structure?

    1. struct {int a;}

    2. struct a_struct {int a;}

    3. struct a_struct int a;

    4. struct a_struct {int a;};

    Answer
  • 14.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        struct sec {
            int a;
            char b;
        };
        int main()
        {
            struct sec s ={25,50};
            struct sec *ps =(struct sec *)&s;
            cout << ps->a << ps->b;
            return 0;
        }

     

    1. 252

    2. 253

    3. 254

    4. 262

    Answer
  • 15.

    What will be the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            struct ShoeType {
               string style;
               double price;
            };
             ShoeType shoe1, shoe2;
             shoe1.style = "Adidas";
             shoe1.price = 9.99;
             cout << shoe1.style << " $ "<< shoe1.price;
             shoe2 = shoe1;
             shoe2.price = shoe2.price / 9;
             cout << shoe2.style << " $ "<< shoe2.price;
             return 0;
        }

     

    1. Adidas $ 9.99
      Adidas $ 1.11

    2. Adidas $ 9.99
      Adidas $ 9.11

    3. Adidas $ 9.99
      Adidas $ 11.11

    4. none of the mentioned

    Answer
  • 16.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        struct Time {
            int hours;
            int minutes;
            int seconds;
        };
        int toSeconds(Time now);
        int main()
        {
            Time t;
            t.hours = 5;
            t.minutes = 30;
            t.seconds = 45;
            cout << "Total seconds: " << toSeconds(t) << endl;
            return 0;
        }
        int toSeconds(Time now)
        {
            return 3600 * now.hours + 60 * now.minutes + now.seconds;
        }

     

    1. 19845

    2. 20000

    3. 15000

    4. 19844

    Answer
  • 17.

    What is the output of this program?

        #include <iostream>
        #include <string.h>
        using namespace std;
        int main()
        {
            struct student {
                int num;
                char name[25];
            };
            student stu;
            stu.num = 123;
            strcpy(stu.name, "John");
            cout << stu.num << endl;
            cout << stu.name << endl;
            return 0;
        }

     

    1. 123
      john

    2. john
      john

    3. compile time error

    4. none of the mentioned

    Answer
  • 18.

    The declaration of structure is also called as?

    1. sructure creator

    2. structure signifier

    3. structure specifier

    4. none of the mentioned

    Answer
  • 19.

    What will happen when the structure is declared?

    1. it will not allocate any memory

    2. it will allocate the memory

    3. it will be declared and initialized

    4. none of the mentioned

    Answer
  • 20.

    What will be used when terminating a structure?

    1. }

    2. ;

    3. ;;

    Answer

© 2017 QuizBucket.org