what is the difference between ..?
-
Hiiii to all I wanna know the difference between the return(0); return 0; return; from a function call...... return(0) and return 0 is same or not ?? Thanking you -------------- :rolleyes: :rolleyes: :rolleyes:
-
Hiiii to all I wanna know the difference between the return(0); return 0; return; from a function call...... return(0) and return 0 is same or not ?? Thanking you -------------- :rolleyes: :rolleyes: :rolleyes:
krish_kumar wrote:
return(0) and return 0 is same or not ??
Yes, it is the same. The parenthesis are here just useless. But, there's a difference between
return;
andreturn 0;
: the first one is used in a function that returns nothing (void) and the second in a function that returns something (here, probably an integer).Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Hiiii to all I wanna know the difference between the return(0); return 0; return; from a function call...... return(0) and return 0 is same or not ?? Thanking you -------------- :rolleyes: :rolleyes: :rolleyes:
krish_kumar wrote:
return(0) and return 0 is same or not
Yes, exactly the same. The addition of brackets makes no difference.
krish_kumar wrote:
return;
This however is totally different, and only valid in a "void" function - i.e. one which doesn't return a result. The difference between them can be illustrated as :-
int DoSomething_1(int val)
{
// some processing
// ...return (0); // has to return a value as it's an "int" function
}
void DoSomething_2(int val)
{
// some processing
// ...return; // must not return a value as it's a "void" function
}
Days spent at sea are not deducted from one's alloted span - Phoenician proverb
-
krish_kumar wrote:
return(0) and return 0 is same or not
Yes, exactly the same. The addition of brackets makes no difference.
krish_kumar wrote:
return;
This however is totally different, and only valid in a "void" function - i.e. one which doesn't return a result. The difference between them can be illustrated as :-
int DoSomething_1(int val)
{
// some processing
// ...return (0); // has to return a value as it's an "int" function
}
void DoSomething_2(int val)
{
// some processing
// ...return; // must not return a value as it's a "void" function
}
Days spent at sea are not deducted from one's alloted span - Phoenician proverb
molesworth wrote:
void DoSomething_2(int val){ // some processing // ... return; // must not return a value as it's a "void" function}
isn't it:
molesworth wrote:
void DoSomething_2(){ // some processing // ... return; // must not return a value as it's a "void" function}
[Edit] sorry for the layout...
-
molesworth wrote:
void DoSomething_2(int val){ // some processing // ... return; // must not return a value as it's a "void" function}
isn't it:
molesworth wrote:
void DoSomething_2(){ // some processing // ... return; // must not return a value as it's a "void" function}
[Edit] sorry for the layout...
Er, no. A "void" function describes what it returns, rather than the number of parameters it has.
Graham Librarians rule, Ook!
-
Er, no. A "void" function describes what it returns, rather than the number of parameters it has.
Graham Librarians rule, Ook!
Thanks Graham, I was just about to say that... :)
Days spent at sea are not deducted from one's alloted span - Phoenician proverb