Declarations and Initializations

Q1:
Point out the error in the following program (if it is compiled with Turbo C compiler).
#include<stdio.h>
int main()
{
    display();
    return 0;
}
void display()
{
    printf('AptitudeCrack.com');
}

A No error

B
display() doesn't get invoked

C
display() is called before it is defined

D None of these

ANS:A - No error

In this program the compiler will not know that the function display() exists. So, the compiler will generate 'Type mismatch in redeclaration of function display()'. To over come this error, we have to add function prototype of function display().
Another way to overcome this error is to define the function display() before the int main(); function.

#include<stdio.h>
void display(); /* function prototype */

int main()
{
    display();
    return 0;
}
void display()
{
    printf('AptitudeCrack.com');
}
Output: AptitudeCrack.com Note: This problem will not occur in modern compilers (this problem occurs in TurboC but not in GCC).



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.