Question

1. (2 points each) Indicate whether each of the following statements are valid or invalid function...

1. (2 points each) Indicate whether each of the following statements are valid or invalid function declarations (prototypes) by highlighting your answer choice (Are they syntactically correct?).

a) double change( X, Y);                           answer:                Valid       Invalid

b) char sign(double x);                               answer:                Valid       Invalid

c) int max(int x, int y, int z)                         answer:                Valid       Invalid

2. (2 points each) Indicate whether each of the following statements are syntactically valid or invalid function headers by highlighting your answer choice.

a) double change( X, Y);                           answer:                Valid       Invalid

b) char sign(double x);                               answer:                Valid       Invalid

c) int max(int x, int y, int z)                         answer:                Valid       Invalid

3. (2 points each) Indicate whether each of the following statements are syntactically valid or invalid function call statements by highlighting your answer choice.

a) change( X, Y);                           answer:                Valid       Invalid

b) sign(double x);                           answer:                Valid       Invalid

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Function declaration: In this, the return type, function name, number and order of parameters and their data types are provided to the compiler.

Syntax: return_type function_name(parameter list);

Therefore,

a.) Answer: Invalid

Reason: The data type of parameters are not defined.

b.) Answer: Valid

Reason: Everything as mentioned in the syntax shown above has been there in the declaration.

c.) Answer: Valid

Reason: Correct as mentioned in the syntax above described.

2. Function header: When defining a function, it contains function header and the body. So the function header is similar to function declaration but there is not semi colon in the last whereas it has curly braces to contain body.

a.) Answer: Invalid

Reason: Does not have data types of the parameters.

b.) Answer: Invalid

Reason: It has everything as mentioned in the syntax but has a semi colon which makes it a declaration rather than function header.

c.) Answer: Valid

Reason: Everything matches with the syntax without a semi colon.

3. Function call: A call has to make to function so as to use it to perform defined task. To make a call parameters needed to be passed along with the function name and If values is returned by the function then need to be store in a variable.

Syntax: function_name(parameters)

a.) Answer: Valid

Reason: The statement is according to the syntax therefore it is valid.

b.) Answer: Invalid

Reason: Since the parameters data type has also been passed so it is invalid.


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
1. (2 points each) Indicate whether each of the following statements are valid or invalid function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT