Thursday, December 20, 2012

What happen if we have 2 return statement in a function

//Program in cpp using 2 return statement in function
#include <iostream>
using namespace std;

int add ()
{
    return 2;
    return 3;
}

int main()
{
    cout << add();
}
  • If  we compiler this program using GCC compiler, it would not give any error or warning.
  • But when we compile this program in Dotnet it give warning message.
___________________________________________________________________________________
//Program in sql using 2 return statement in function
create function ab()
returns int
as
    begin
        return 100
        return 120
    end
   
print dbo.ab()

This is not give the error because the sql compiler is not enough smart

MORAL of the story: it totally dependent on the compiler, that it gives warning or not, when we use 2 return statement in a function.

No comments:

Post a Comment