My Report

C++ Pointer Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

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

2. When does the void pointer can be dereferenced?

3. A void pointer cannot point to which of these?

4. What will be the output of the following C++ code?

    #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;
    } 

5. What will be the output of the following C++ code?

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

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

7. What we can't do on a void pointer?

8. What will be the output of the following C++ code?

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

9. What will be the output of the following C++ code?

    #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;
    } 

10. What will be the output of the following C++ code?

    #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;
    } 

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.