Declarations and Initializations

Q1:
Point out the error in the following program.
#include<stdio.h>
int main()
{
    int (*p)() = fun;
    (*p)();
    return 0;
}
int fun()
{
    printf('AptitudeCrack.com\n');
    return 0;
}

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

B
Error: fun() prototype not defined

C No error

D None of these

ANS:A -

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

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<stdio.h>
int fun(); /* function prototype */

int main()
{
    int (*p)() = fun;
    (*p)();
    return 0;
}
int fun()
{
    printf('AptitudeCrack.com\n');
    return 0;
}



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.