Question

In: Computer Science

Short circuit evaluation is when the language evaluates the first portion of a BOOLEAN expression and...

Short circuit evaluation is when the language evaluates the first portion of a BOOLEAN expression and if, knowing the result of the value, then skips the evaluation of the second expression. For example, A & B is false if A is false... no need to evaluate B. A similar scenario is true for OR. Most languages implement short circuit evaluation

create a program for the following languages: FORTRAN

Write the summary of your result

An example could look like:

function f()

{ write('I have been evaluated');
      return(1);

}

main()
{   int i=1;

if ( i ==0 && f() )
then write ('true')
else   write ('false)

} 33

Solutions

Expert Solution

Given the above example following is the summary for the same.

function f()

{ write('I have been evaluated');
      return(1);

}

main()
{   int i=1;

if ( i ==0 && f() )
then write ('true')
else   write ('false)

}

In the above case, as i is not equal to 0, thus it will calculate f() thus "i have been evaluated" string will be printed.
Then as the function is returning 1, so it will print true.

Next Example:

function f()

{ write('I have been evaluated');
      return(1);

}

main()
{   int i=1;

if ( i ==1 && f() )
then write ('true')
else   write ('false)

}

So in the above case as the i is equal to 1 thus the next statement i.e evaluation of f() is not done. Then it will print only true.

Example:

function f()

{ write('I have been evaluated');
      return(1);

}

main()
{   int i=1;

if ( i ==1 || f() )
then write ('true')
else   write ('false)

}

In this case too as i is equal to 1, thus it will not calculate the function as there is an OR operator. Thus it will simply print "true" but not "I have been evaluated"

That was a nice question to answer
Friend, If you have any doubts in understanding do let me know in the comment section. I will be happy to help you further.
Please like if you think effort deserves like.
Thanks


Related Solutions

Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2...
Postfix Evaluation (JAVA PROGRAMMING) Write class PostfixEva1uator that evaluates a postfix expression such as 6 2 + 5 * 8 4 / - The program should read a postfix expression consisting of single digits and operators into a StringBuilder, The program should read the expression and evaluate it (assume it's valid). The algorithm to evaluate a postfix expression is shown below. Use +, -, *, /, and ^. ^ is the exponent. Append a right parenthesis ') ' to the...
A manufacturing company produces electrical insulators. If the insulators break when in use, a short circuit...
A manufacturing company produces electrical insulators. If the insulators break when in use, a short circuit is likely to occur. To test the strength of the insulators, destructive testing is carried out to determine how much force is required to break the insulators. Force is measured by observing the number of pounds of force applied to the insulator before it breaks. The following data (stored in Force) are from 30 insulators subjected to this testing: At the 0.05 level of...
A manufacturing company produces electrical insulators. If the insulators break when in use, a short circuit...
A manufacturing company produces electrical insulators. If the insulators break when in use, a short circuit is likely to occur. To test the strength of the insulators, destructive testing is carried out to determine how much force is required to break the insulators. Force is measured by observing the number of pounds of force applied to the insulator before it breaks. The data shown below are from 30 insulators subjected to this testing: Force 1870 1728 1656 1610 1634 1784...
Otacnu Manufacturing Inc. builds electric insulators. If the insulators break when in use, a short circuit...
Otacnu Manufacturing Inc. builds electric insulators. If the insulators break when in use, a short circuit is likely to occur. To test the strength of the insulators, destructive testing in high-powered labs is carried out to determine how much force is required to break the insulators. The force is measured by observing how many pounds must be applied to the insulator before it breaks. The force measurements, collected from a sample of 30 insulators and stored in the Force are:...
Rising Edge Detector: The rising-edge detector is a circuit that generates a short one-clock-cycle tick when...
Rising Edge Detector: The rising-edge detector is a circuit that generates a short one-clock-cycle tick when the input signal changes from 0 to 1. It is usually used to indicate the onset of a slow time-varying input signal. Moore machine state diagram for the rising-edge detector is shown in Figure 6. a. Draw the state diagram for the rising edge detector b. Adapt the Code Example 1 to implement the detector in Verilog
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT