need help with this question

double fun(double *x); // code given somewhere else

void main ()
{
double a [ ] {3.0, 1.0, 4.0, 1.0, 5.0};
double b = fun (a);
. . .

a) Is this (partial) code syntactically correct?
b) What piece of information does the code in "fun" have to obtain from another source?
a) Is this (partial) code syntactically correct?

Yeah, if you add at minimum:
1
2
return 0;
}

after the declaration of b.

b) What piece of information does the code in "fun" have to obtain from another source?

What do you mean by "another source"?
Last edited on
It is not syntactically correct, but maybe not why you expect.
The C++ standard says that programs' main function shall (must) return int.

3.6.1 Main function [basic.start.main]
An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation defined. All implementations shall allow both of the following definitions of main:
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }


In other words: void main() is wrong.

BobMorane wrote:

Yeah, if you add at a minimum:
1
2
return 0;
}

after the declaration of b


Unique among all functions returning non-void, C++'s main function does not require a return statement.
3.6.1 Main function [basic.start.main]
If control reaches the end of main without encountering a return statement, the effect is that of executing return 0;
Unique among all functions returning non-void, C++'s main function does not require a return statement.


Wow, I did not know that! Thanks.
closed account (1vRz3TCk)
b) What piece of information does the code in "fun" have to obtain from another source?
Hint: double b = fun (a); a is an array.
Topic archived. No new replies allowed.