1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Neko [114]
3 years ago
9

Functional side effects: 15) Given the following Java/C++ like code. Assuming function calls (operands) are evaluated from left-

to-right, one at a time. a) What outputs are printed to the screen? int a = 4; // global variable int fun1() { a = 2; return 3; } int fun2() { return a; } void main() { int x = fun1() + fun2(); System.out.println("x = " + x); } Answer: x = b) What outputs are printed to the screen? int a = 4; // global variable int fun1() { a = 2; return 3; } int fun2() { return a; } void main() { int x = fun2() + fun1(); System.out.println("x = " + x); } Answer: x =
Computers and Technology
1 answer:
tigry1 [53]3 years ago
7 0

Answer:

a. x = 5

b. x = 7

Explanation:

a)

OUTPUT: x = 5

In the main() function, fun1() is evaluated first and it updates the value of the global variable to 2 and returns 3.

The second function returns the value of the global variable 'a' and this variable has value 2.

So,

x = 3 + 2

x = 5

b)

OUTPUT: x = 7

In the main() function, fun2() is evaluated first and it returns 4 because global variable 'a' is initialized with value 4.

The second function fun()1 will returns the value 3.

So,

x = 4 + 3

x = 7

You might be interested in
Write a class called MagicSquare, which contains a single method called check that accepts a two-dimensional array as an argumen
ira [324]

Answer:

public class MagicSquare {

   public static void main(String[] args) {

       int[][] square = {

               { 8, 11, 14, 1},

               {13, 2, 7,12},

               { 3, 16, 9, 6},

               {10, 5, 4, 15}

       };

       System.out.printf("The square %s a magic square. %n",

               (isMagicSquare(square) ? "is" : "is not"));

   }

   public static boolean isMagicSquare(int[][] square) {

       if(square.length != square[0].length) {

           return false;

       }

       int sum = 0;

       for(int i = 0; i < square[0].length; ++i) {

           sum += square[0][i];

       }

       int d1 = 0, d2 = 0;

       for(int i = 0; i < square.length; ++i) {

           int row_sum = 0;

           int col_sum = 0;

           for(int j = 0; j < square[0].length; ++j) {

               if(i == j) {

                   d1 += square[i][j];

               }

               if(j == square.length-i-1) {

                   d2 += square[i][j];

               }

               row_sum += square[i][j];

               col_sum += square[j][i];

           }

           if(row_sum != sum || col_sum != sum) {

               return false;

           }

       }

       return d1 == sum && d2 == sum;

   }

}

5 0
3 years ago
The working window of a presentation is the _____.
stepan [7]
The answer would be slide
8 0
4 years ago
Read 2 more answers
____ elements are arranged to show which tasks must be completed before subsequent dependent tasks can begin.
Masteriza [31]
The answer is Gantt Chart
5 0
4 years ago
Your objective is to create a set of files to be used as ‘flags’ that will be stored on computers used in a ‘capture the flag’ c
Semenov [28]

The following are the steps involved in the Process validation to the industry standard,

1)     Design of the process

2)     Qualification of the process

3)     Verification of the process

Explanation:

Validation is the process of finding whether the process meets its expected outcome.

1)     Construct knowledge about the process to be performed and establish a final design.

2)     Evaluation of the designed process is being done at this stage to rectify the errors and changes can be done.

Test the process to check whether the expected goal of the process being designed is achieved or not.

5 0
4 years ago
A top level class without any modifier is accessible to
LenKa [72]

Answer: A top level class without any modifier is accessible to any class within the same package.

Explanation: A top level class is class whose declaration occur in the body of their own class therefore it is not a nested class.It cannot be declared in any other class.Private modifier is not allowed in the top level class because there would be no access in the class. Therefore top level class which does not have any modifier can be accessed by any class within the same package .

4 0
4 years ago
Other questions:
  • What is computer engineering?
    11·1 answer
  • What happens to the data in rom when the power is turned off?
    10·1 answer
  • Why must programs written in a high-level language be translated into machine language?
    5·1 answer
  • How long does it take a packet of length 1,000 bytes to propagate over a link of distance 2,500 km, propagation speed 2.5 · 108
    8·2 answers
  • How to program a concrete Damage-Plasticity material?
    5·1 answer
  • 4. How could you apply some of the ideas, principles, or structures of coding to fields of study, industries, or tasks outside o
    8·1 answer
  • Given the three thread states: running, runnable (i.e., ready), and blocked (i.e., waiting), state which of the six possible thr
    13·1 answer
  • Five Star Retro Video rents VHS tapes and DVDs to the same connoisseurs who like to buy LP record albums. The store rents new vi
    13·1 answer
  • CAN SOMEONE PLEASE HELP ME WITH THIS PLEASE ?!!!!!!!!
    14·1 answer
  • 2 4.1.2 Quiz: Information Systems and Business Planning
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!