C++ quiz questions

C++ interview questions

  • 1.

    What will be the output of this program?

        #include <stdio.h>
        using namespace std;
        int array1[] = {1200, 200, 2300, 1230, 1543};
        int array2[] = {12, 14, 16, 18, 20};
        int temp, result = 0;
        int main()
        {
            for (temp = 0; temp < 5; temp++) {
                result += array1[temp];
            }
            for (temp = 0; temp < 4; temp++) {
                result += array2[temp];
            }
            cout << result;
            return 0;
        }

     

    1. 6553

    2. 6533

    3. 6522

    4. 12200

    Answer
  • 2.

    Which of the following gives the memory address of the first element in array?

    1. array[0];

    2. array[1];

    3. array(2);

    4. array;

    Answer
  • 3.

    Which of the following accesses the seventh element stored in array?

    1. array[6];

    2. array[7];

    3. array(7);

    4. array;

    Answer
  • 4.

    What is a array?

    1. An array is a series of elements of the same type in contiguous memory locations

    2. An array is a series of element

    3. An array is a series of elements of the same type placed in non-contiguous memory locations

    4. None of the mentioned

    Answer
  • 5.

    What is the index number of the last element of an array with 9 elements?

    1. 9

    2. 8

    3. 0

    4. Programmer-defined

    Answer
  • 6.

    Which of the following correctly declares an array?

    1. int array[10];

    2. int array;

    3. array{10};

    4. array array[10];

    Answer
  • 7.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            char *ptr;
            char Str[] = "abcdefg";
            ptr = Str;
            ptr += 5;
            cout << ptr;
            return 0;
        }

     

    1. fg

    2. cdef

    3. defg

    4. abcd

    Answer
  • 8.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            char arr[20];
            int i;
            for(i = 0; i < 10; i++)
                *(arr + i) = 65 + i;
            *(arr + i) = '\0';
            cout << arr;
            return(0);
        }

     

    1. ABCDEFGHIJ

    2. AAAAAAAAAA

    3. JJJJJJJJ

    4. none of the mentioned

    Answer
  • 9.

    The correct statement for a function that takes pointer to a float, a pointer to a pointer to a char and returns a pointer to a pointer to a integer is

    1. int **fun(float**, char**)

    2. int *fun(float*, char*)

    3. int ***fun(float*, char**)

    4. int ***fun(*float, **char)

    Answer
  • 10.

    What is the output of this program?

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

     

    1. 5

    2. 10

    3. 15

    4. it will return some random number

    Answer
  • 11.

    What will happen in this code?
        int a = 100, b = 200;
        int *p = &a, *q = &b;
        p = q;

    1. b is assigned to a

    2. p now points to b

    3. a is assigned to b

    4. q now points to a

    Answer
  • 12.

    Which of the following is illegal?

    1. int *ip;

    2. string s, *sp = 0;

    3. int i; double* dp = &i;

    4. int *pi = 0;

    Answer
  • 13.

    Which one of the following is not a possible state for a pointer.

    1. hold the address of the specific object

    2. point one past the end of an object

    3. zero

    4. point to a tye

    Answer
  • 14.

    Choose the right option

        string* x, y;

    1. x is a pointer to a string, y is a string

    2. y is a pointer to a string, x is a string

    3. both x and y are pointer to string types

    4. none of the mentioned

    Answer
  • 15.

    The operator used for dereferencing or indirection is ____

    1. *

    2. &

    3. ->

    4. –>>

    Answer
  • 16.

    What does the following statement mean?

        int (*fp)(char*)

    1. pointer to a pointer

    2. pointer to an array of chars

    3. pointer to function taking a char* argument and returns an int

    4. function taking a char* argument and returning a pointer to int

    Answer
  • 17.

    Identify the type of the variables.

        typedef char* CHAR;
        CHAR p,q;

    1. char*

    2. char

    3. CHAR

    4. unknown

    Answer
  • 18.

    Identify the incorrect statements.

        int var = 10;
        int *ptr = &(var + 1); //statement 1
        int *ptr2 = &var; //statement 2
        &var = 40; //statement 3

    1. Statement 1 and 2 are wrong

    2. Statement 2 and 3 are wrong

    3. Statement 1 and 3 are wrong

    4. All the three are wrong

    Answer
  • 19.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        int main()
        {
            int a = 10;
            if (a < 10) {
                for (i = 0; i < 10; i++)
                   cout << i;
            }
            else {
                cout << i;
            }
            return 0;
        }

     

    1. 0123456789

    2. 123456789

    3. 0

    4. error

    Answer
  • 20.

    What is the output of this program?

        #include <iostream>
        using namespace std;
        void addprint()
        {
            static int s = 1;
            s++;
            cout << s;
        }
        int main()
        {
            addprint();
            addprint();
            addprint();
            return 0;
        }

     

    1. 234

    2. 111

    3. 123

    4. 235

    Answer

© 2017 QuizBucket.org