Pointers


  1. What is the output of this program?
    #include 
    using namespace std;
    void function(int p)
    {
    cout << p;
    }
    int main()
    {
    void (*num)(int);
    num = &function;
    (*num)( 3 );
    num( 11 );
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    As we are calling the function two times with the different value, So it is printing as 311.


  1. What is the output of this program?
    #include 
    using namespace std;
    int addition(int num1, int num2)
    {
    return num1 + num2 + 13;
    }
    int calculation(int num1, int num2, int (*funcall)(int, int))
    {
    return (*funcall)(num1, num2);
    }
    int main()
    {
    int n;
    int (*plus)(int, int) = addition;
    n = calculation(12, 20, plus);
    cout << n;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, we are adding two numbers with 13, So we got the output as 45.



  1. What is the default calling convention for a compiler in c++?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    __cdecl


  1. What will we not do with function pointers?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    As it is used to execute a block of code, So we will not allocate or deallocate memory.