Pointers


  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    int num = 10;
    void *ptr = #
    int *ptr0 = static_cast(ptr);
    cout << *ptr0;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    We just casted this from void to int, so it prints 10.


  1. What we can’t do on a void pointer?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Because the void pointer is used to cast the variables only, So pointer arithmetic can’t be done in a void pointer.



  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    int p = 10, add;
    void *ptr = &p;
    double q = 2.24;
    ptr = &q;
    add = p + q;
    cout << add << '\n' << ptr;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    In this program, we are just adding the two values and printing it.


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











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Because it doesn’t know the type of object it is pointing to, So it can point to all objects.



  1. What is the output of this program?
    #include 
    using namespace std;
    int main()
    {
    int num;
    char ch;
    void *value;
    num = 5;
    ch = 'd';
    value = #
    cout << "The value points to the integer value " << value << endl;
    value = &ch;
    cout << "The value now points to the character " << value;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Because the data points to the address value of the variables only, So it is printing the memory address of these two variable.