Loading...

C++ Multiple Choice Questions

Our C++ questions and answers focuses on all areas of C++ programming language covering 100+ topics in C++

C++ Pointers MCQ | Set 2

C++ Pointers | Set 2


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

a) p is pointer to function
b) p is array of pointer to function
c) p is pointer to such function which return type is the array
d) p is pointer to array of function



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

a) 2
b) 4
c) 8
d) 0



13. What will be the output of the following C++ code?
#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) << [1[a]];

    return 0;
}

a) 15 18 21
b) 21 21 21
c) 24 24 24
d) Compile time error



14. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {

    int i;
    const char *arr[] = {"c", "c++", "java", "VBA"};
    const char *(*ptr)[4] = &arr;
    cout << ++(*ptr)[2];

    return 0;
}

a) ava
b) java
c) c++
d) compile time error



15. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {

    int arr[] = {4, 5, 6, 7};
    int *p = (arr + 1);
    cout << *p;

    return 0;
}

a) 4
b) 5
c) 6
d) 7



16. What will happen in the following C++ code snippet?
#include <iostream>
using namespace std;
int main() {

    int arr[] = {4, 5, 6, 7};
    int *p = (arr + 1);
    cout << arr;

    return 0;
}

a) 4
b) 5
c) address of arr
d) 7



17. What will be the output of the following C++ code?
#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;
}

a) 10,20,30,40,50,
b) 1020304050
c) compile error
d) runtime error



18. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main() {

    int arr[] = {4, 5, 6, 7};
    int *p = (arr + 1);
    cout << *arr + 9;

    return 0;
}

a) 12
b) 5
c) 13
d) error



19. The void pointer can point to which type of objects?

a) int
b) float
c) double
d) all of the mentioned



20. When does the void pointer can be dereferenced?

a) when it doesn’t point to any value
b) when it cast to another type of object
c) using delete keyword
d) using shift keyword



- Related Topics