Skip to main content

What is a prototype?

More
15 years 7 months ago #27555 by ardeef
What is a prototype? was created by ardeef
Hi!

I cant find a more appropriate place to post my question, but just in case you want to reply. I was reading a programming book and came accross with the word prototype in the usage of a printf() function.that is, the prototype of printf() is:

boolean printf(string format [, mixed args])

but in the example,

printf("I am %d years old.", 25);

i cant see now the boolean. why there is a need to put boolean in the prototype but in actual, you really dont need to put it.

My understanding about prototype is that, it is a format that need to follow to avoid syntax error.

Please enlighten me.
More
15 years 7 months ago #27556 by KiLLaBeE
Replied by KiLLaBeE on topic Re: What is a prototype?
You can also think of a prototype in the context of programming as a "template," and "template" tells you what to supply the function with, and what to expect in return. The "template" basically gives you an idea of how to make the function work.

printf(), being a function, has inputs that it can take in, and has an output that it can put out. As observed, the words within () in the printf function define what inputs the printf function can take in, and boolean defines what kind of output the printf function can output.

Because the printf function is so widely used in programming examples, it's not difficult to understand how it operates and how to use it...you should mostly concern yourself with the input and output parameters of functions that you're not familiar with because if you don't supply the functions with the correct inputs, or you don't define the correct output that they should output, they may not work or work incorrectly.

I'm guessing that you just started your programming book...if so, when you start learning about functions and how to make them, you'll better understand.
Time to create page: 0.144 seconds