C++ quiz questions

C++ interview questions

  • 1.

    The difference between x and ‘x’ is

    1. The first one refers to a variable whose identifier is x and the second one refers to the character constant x

    2. The first one is a character constant x and second one is the string literal x

    3. Both are same

    4. None of the mentioned

    Answer
  • 2.

    Regarding following statement which of the statements is true?
        const int a = 100;

    1. Declares a variable a with 100 as its initial value

    2. Declares a construction a with 100 as its initial value

    3. Declares a constant a whose value will be 100

    4. Constructs an integer type variable with a as identifier and 100 as value

    Answer
  • 3.

    Which of the following statement is not true about preprocessor directives?

    1. These are lines read and processed by the preprocessor

    2. They do not produce any code by themselves

    3. These must be written on their own line

    4. They end with a semicolon

    Answer
  • 4.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        #define PI 3.14159
        int main ()
        {
            float r = 2;
            float circle;
            circle = 2 * PI * r;
            cout << circle;
            return 0;
        }

     

    1. 12.5664

    2. 13.5664

    3. 10

    4. compile time error

    Answer
  • 5.

    What is the output of this program?

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

     

    1. 5

    2. 6

    3. Error

    4. None of the mentioned

    Answer
  • 6.

    How the constants are declared?

    1. const keyword

    2. #define preprocessor

    3. both a and b

    4. None of the mentioned

    Answer
  • 7.

    What are the parts of the literal constants?

    1. integer numerals

    2. floating-point numerals

    3. strings and boolean values

    4. all of the mentioned

    Answer
  • 8.

    The constants are also called as

    1. const

    2. preprocessor

    3. literals

    4. none of the mentioned

    Answer
  • 9.

    What is the output of this program?

       #include <iostream>
       using namespace std;
       int main()
       {
            int arr[] = {4, 5, 6, 7};
            int *p = (arr + 1);
            cout << *arr + 9;
            return 0;
       }

     

    1. 12

    2. 5

    3. 13

    4. error

    Answer
  • 10.

    What is the output of this program?

       #include <iostream>
       using namespace std;
       int main ()
       {
           int numbers[5];
           int * p;
           p = numbers;  *p = 10;
           p++;  *p = 20;
           p = &numbers[2];  *p = 30;
           p = numbers + 3;  *p = 40;
           p = numbers;  *(p + 4) = 50;
           for (int n = 0; n < 5; n++)
               cout << numbers[n] << ",";
           return 0;
       }

     

    1. 10,20,30,40,50,

    2. 1020304050

    3. compile error

    4. runtime error

    Answer
  • 11.

    What is the output of this program?

       #include <iostream>
       using namespace std;
       int main()
       {
           int arr[] = {4, 5, 6, 7};
           int *p = (arr + 1);
           cout << arr;
           return 0;
       }

     

    1. 4

    2. 5

    3. address of arr

    4. 7

    Answer
  • 12.

    What is the output of this program?

       #include <iostream>
       using namespace std;
       int main()
       {
           int arr[] = {4, 5, 6, 7};
           int *p = (arr + 1);
           cout << *p;
           return 0;
       }

     

    1. 4

    2. 5

    3. 6

    4. 7

    Answer
  • 13.

    What is the output of this program?

       #include <iostream>
       using namespace std;
       int main()
       {
           int i;
           char *arr[] = {"C", "C++", "Java", "VBA"};
           char *(*ptr)[4] = &arr;
           cout << ++(*ptr)[2];
           return 0;
       }

     

    1. ava

    2. java

    3. c++

    4. compile time error

    Answer
  • 14.

    What is the output of this program?

       #include <iostream>
       using namespace std;
       int main()
       {
           int a[2][4] = {3, 6, 9, 12, 15, 18, 21, 24};
           cout << *(a[1] + 2) << *(*(a + 1) + 2) << 2[1[a]];
           return 0;
       }

     

    1. 15 18 21

    2. 21 21 21

    3. 24 24 24

    4. Compile time error

    Answer
  • 15.

    What is size of generic pointer in C++ (in 32-bit platform) ?

    1. 2

    2. 4

    3. 8

    4. 0

    Answer
  • 16.

    What is meaning of following declaration?
    int(*p[5])();

    1. p is pointer to function.

    2. p is array of pointer to function.

    3. p is pointer to such function which return type is array.

    4. p is pointer to array of function.

    Answer
  • 17.

    What is the output of this program?

        #include <stdio.h>
        using namespace std;
        int main()
        {
            int array[] = {10, 20, 30};
            cout << -2[array];
            return 0;
        }

     

    1. -15

    2. -30

    3. compile time error

    4. garbage value

    Answer
  • 18.

    What is the output of this program?

        #include <stdio.h>
        using namespace std;
        int main()
        {
            char str[5] = "ABC";
            cout << str[3];
            cout << str;
            return 0;
        }

     

    1. ABC

    2. ABCD

    3. AB

    4. None of the mentioned

    Answer
  • 19.

    What is the output of this program?

        #include <stdio.h>
        using namespace std;
        int main()
        {
            int a = 5, b = 10, c = 15;
            int arr[3] = {&a, &b, &c};
            cout << *arr[*arr[1] - 8];
            return 0;
        }

     

    1. 15

    2. 18

    3. garbage value

    4. compile time error

    Answer
  • 20.

    What will be the output of the this program?

        #include <stdio.h>
        using namespace std;
        int main ()
        {
            int array[] = {0, 2, 4, 6, 7, 5, 3};
            int n, result = 0;
            for (n = 0; n < 8; n++) {
                result += array[n];
            }
            cout << result;
            return 0;
        }

     

    1. 25

    2. 26

    3. 27

    4. None of the mentioned

    Answer

© 2017 QuizBucket.org