Sunday, July 26, 2009

When i compiled simple below pgm in dev++it compile & gave o/p.but in turbo c, it wll give error.why?

Error is : Call to undefine fn 'display' in fn main.








#include%26lt;stdio.h%26gt;








main()


{


printf("\n Hello");


display();


}


display()


{


printf("\n WELCOME!");





}

When i compiled simple below pgm in dev++it compile %26amp; gave o/p.but in turbo c, it wll give error.why?
It is basically telling you that it does not know the function "display()" that you use in your "main()" function. So what you need to do is either move the function before main. or declare a function prototype for it at the top.





It is also better to put a return type for your function. If you are not returning anything, you should put void.





So your code should be:





#include%26lt;stdio.h%26gt;





void display(); // function prototype for display





int main()


{


printf("\n Hello");


display();





return 0;


}





void display()


{


printf("\n WELCOME!");





}


No comments:

Post a Comment