In a function definition, it's not needed to name the variables, so
basically this will work:
void F1(int, int);
> void F1(int a, int b) {
> //some code;
> }
>
actually when you write:
> void F1(int *males*, int *females*);
>
*males* and *females* are completely ignored by the compiler, they are
treated like a comment and don't affect the code at all.
It could be used to complete the sense of *definition*, which is defining
the variables by writing a name for them. Imagine this function definition
is written in a header file and you are only distributing the header file,
it will make a lot of sense to have a name for each variable in the
definition.
In the other side, some IDE use those names in the auto-complete action to
remind you about the parameters while trying to call the function.
-- Amahdy
www.amahdy.net
On Sun, Aug 21, 2011 at 13:51, mandy <[email protected]> wrote:
> #include
> using namespace std;
>
> int main() {
> int Boys = 3, Girls = 5;
> void F1(int males, int females);
> void F2(int &m, int &f);
>
> F1(Boys, Girls);
> cout << "\nAfter calling F1, within main()";
> cout << "\n\tBoys = " << Boys; // #2
> cout << "\n\tGirls = " << Girls;
>
> F2(Boys, Girls);
> cout << "\nAfter calling F2, within main()";
> cout << "\n\tBoys = " << Boys; // #4
> cout << "\n\tGirls = " << Girls;
> }
>
> void F1(int b, int g) {
> b += 3, g += 4;
> cout << "\nF1";
> cout << "\n\tBoys = " << b; // #1
> cout << "\n\tGirls = " << g;
> }
>
> void F2(int &b, int &g) {
> b = b + 8, g = g + 5;
> cout << "\nF2";
> cout << "\n\tBoys = " << b; // #3
> cout << "\n\tGirls = " << g;
> }
>
> Question 1: What is the output of the Boys variable on the marked lines?
> A) #1: 6
> #2: 3
> #3: 11
> #4: 11
> B) #1: 6
> #2: 3
> #3: 11
> #4: 3
> C) #1: 6
> #2: 6
> #3: 11
> #4: 11
> D) It outputs nothing because it does not compile or run.
> pls tell me during declaration and definition variable must be same,but
> here is something different.And ans is (A). Thanks......
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-codejam" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-code/-/e4EUV44QQzIJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.