return program
-
i want to know here that when i write a function like this
int add (int a,int b) { int sum=0; sum=a+b; return sum; }
i return sum but return sum to where.... that what i hope to know thank's for allTo Be Or Not To Be (KARFER)
The value of sum is returned to the caller of add(). Somewhere else in your code you'd call add... int SumFromAdd = add(2,3); //SumFromAdd == 5 You can also choose to igore return values... add(2,3); // add() has been called but the return value wasn't used Note that there's no need to initialize sum to 0 in your function since the next line you initialize it to the sum of the two passed integers. You could shorten your function to: int add (int a,int b) { return a+b; } Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
i want to know here that when i write a function like this
int add (int a,int b) { int sum=0; sum=a+b; return sum; }
i return sum but return sum to where.... that what i hope to know thank's for allTo Be Or Not To Be (KARFER)
Sometimes you need to return value so you use of this cause here is two samples:
int add (int a,int b)
{
int sum;
sum=a+b;
return sum;
}void test()
{
int c;
c=add(2,2);
}
////////////////////////////////////Cstring add ()
{
CString str;
SYSTEMTIME st;
GetLocalTime(&st);
str.Format("%d:%d:%d:",st.wHour,st.wMinute,st.wSecond);return str;
}
void test()
{
MessageBox(add());
}
WhiteSky