Home / C Programming / Declarations and Initializations :: Discussion

Discussion :: Declarations and Initializations

  1. Point out the error in the following program.

    #include
     int main()
     {     
         int (*p)() = fun;   
         (*p)();    
         return 0; 
    } int fun() 
    {
        printf("Freshergate.com\n");  
       return 0;
    } 
    

     

  2. A.

    Error: in int(*p)() = fun;

    B.

    Error: fun() prototype not defined

    C.

    No error

    D.

    None of these

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The compiler will not know that the function int fun() exists. So we have to define the function prototype of int fun();
    To overcome this error, see the below program

    #include

    int fun(); /* function prototype */

    int main()

    {

        int (*p)() = fun;  

        (*p)();

        return 0;

    }

    int fun()

    {

        printf("Freshergate.com\n");

        return 0;

    }

     


Be The First To Comment