Computer Science : Post-Conditions

Study concepts, example questions & explanations for Computer Science

varsity tutors app store varsity tutors android store

Example Questions

Example Question #1 : Post Conditions

double square(double n){

return n*n;


What MUST be true immediately after the above code snippet has run?

Possible Answers:

It is impossible to tell.

The result will be a positive number.

The value of the input parameter changes.

The result will be a negative number.

The result will be stored in a new variable.

Correct answer:

The result will be a positive number.


Squaring a real number will always produce a positive number. The result does not have to be stored in a new variable; it could be a value that is only needed for a one-off expression, thus, not worthy to be stored in memory. Lastly, since the input was passed by value and not by reference, its initial value will stay the same.

Learning Tools by Varsity Tutors