ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The answer to it are
1. the function prototype is required only when it is called before it is defined during the run of the code....
2. yes the function prototype can be declared in each function that calls this particular function, instead of being declared in the beginning of the file...
if it is done so then this declaration would be local to the function... a better practise is to define all the functions at the begining of the file... before the main
3. it is immaterial to declare if the function is defined before it is first called....
Originally posted by hiteshmaisheri The answer to it are
1. the function prototype is required only when it is called before it is defined during the run of the code....
But my program works even if I don't use function prototype(assuming function is called prior to its definition)
Just because it works, it doesn't mean it is correct. It may only work with your test case or it could fail on other compilers. The compiler uses the function prototype to determine if the call you are making is of the correct type, etc. If the compiler doesn't know, it guesses. I think it basically assumes that everything in the function call is an int. Depending on what you are doing, that may or may not work.
This is one of those cases where C doesn't do a lot to stop you from shooting yourself in the foot. It is up to the programmer to protect himself by using the prototypes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.