Mystic
•
29 Jan 2007, 13:28
•
Journals
So has anyone got any mystik news ?
random pic:
#include <iostream>
int AreaCube(int length, int width = 25, int height = 1);
int main()
{
int length = 100;
int width = 50;
int height = 2;
int area;
area = AreaCube(length, width, height);
std::cout << "First area equals: " << area << "\n";
area = AreaCube(length, width);
std::cout << "Second time area equals: " << area << "\n";
area = AreaCube(length);
std::cout << "Third time area equals: " << area << "\n";
char response;
std::cin >> response;
return 0;
}
int AreaCube(int length, int width, int height)
{
return (length * width * height);
}
what is its output? first one gets a nekid pic of loekino!
random pic:
#include <iostream>
int AreaCube(int length, int width = 25, int height = 1);
int main()
{
int length = 100;
int width = 50;
int height = 2;
int area;
area = AreaCube(length, width, height);
std::cout << "First area equals: " << area << "\n";
area = AreaCube(length, width);
std::cout << "Second time area equals: " << area << "\n";
area = AreaCube(length);
std::cout << "Third time area equals: " << area << "\n";
char response;
std::cin >> response;
return 0;
}
int AreaCube(int length, int width, int height)
{
return (length * width * height);
}
what is its output? first one gets a nekid pic of loekino!
bb
i'm not a programmer or even trying 2
unless you've overloaded the AreaCube() method.
From what I remember from Java this won't work. First you set the integer AreaCube() and give it the values "length, width = 25, height = 1", and later on you create the same integer again without values. Unless you give length, width and hight a value outside of the integer it should give an error.
Could be wrong though, don't know how C++ compares to Java n aLL. :<
First area = 10000 (100 * 50 * 2)
Second area = 5000 (100 * 50 *1)
Third area = 2500 (100 * 25 * 1)
It's good example of how default values of parameters work. When you call AreaCube with 3 parameters default values are not used. However, if you provide less than 3 parameters, compiler will assume that remaining parameters are set to values specified in function prototype, in 2nd line (right after #include).
And no, "return 0" is not something you put in every c++ code. It's statement that ends current function with 0 (integer) as result. If this is last function (read: it's main(), called right after starting application) then value you're returning there will go to your OS / environment to determine if app stopped running due to some error / bug / problem or was just closed.
0 determinates that there were no errors.
Second time area equals: 5000
Third time area equals: 2500