function prototype vs non prototype

hello i just want to ask if there is a difference between prototype function and non prototype.
example:

1
2
3
4
5
6
7
8
9
10
11
int add(int x,int y)
 {
 return x+y;
 }
int main()
{                                     //non prototype
cout<<"Enter two integers: ";         
int x,y;
cin>>x>>y;
cout<<add(x,y)
}


and this

1
2
3
4
5
6
7
8
9
10
11
12
13
int add(int x,int y);

int main()
{
cout<<"Enter two integers: ";         
int x,y;                                   //prototype
cin>>x>>y;
cout<<add(x,y)
}
int add(int x,int y)
 {
 return x+y;
 }

No, there is no change in behavior in those two examples.
hello miniipaa
can you give me example that shows the difference of prototype and non?
There's no change in behaviour. But declaring the prototypes at the start means the actual function definitions can be placed in any order, even if a particular function needs to call another function which is further down.

Sometimes essential when two functions each can call the other. Without prototypes, one would always be invisible to the other.
can you give me example that shows the difference of prototype and non?

The only difference is a matter of style. IMO, declaring protoypes first is prone to errors. If you change a function, you must also change the prototype. This can get overlooked in larger programs.

Either style is prone to the compiler incorrectly deducing a signature because of a missing function definition (function first) or incorrect prototype (prototype first). This should generate a compiler warning and will cause a linker error when the implementation for the missing signature is not found.

Of course if you're writing in C++, you seldom need function prototypes since most if not all functions should be declared in classes.
I see thanks all my question has been answered thank you all
Topic archived. No new replies allowed.