Add a score to your achieve of correctly answered questions. Which then will determine how much of a Genius you are.
Answer:
The solution code is written in Java.
- public static void swapArrayEnds(int myArray[]){
- int lastIndex = myArray.length-1;
- int temp = myArray[0];
- myArray[0] = myArray[lastIndex];
- myArray[lastIndex ] = temp;
- }
Explanation:
First create the swapArrayEngs method that take one input array parameter (Line 1).
Since we need to swap the first and last element of the array, we need to get the first index and last index of the array. The first index is 0 and the last index can be calculated by subtracting the length of array from 1 (Line 2).
Next, we can create a temp variable to hold the value of the first element (Line 3). Then we use the lastIndex the get the value of last element and assign it to the first element of array (Line 4). Lastly, we assign the temp (holding the initial first element value) to the last element of array (Line 5).
Answer:
True
Explanation:
The ESP register acts as an indirect operand pointing to the top of the stack at any time.
Stack grows downwards from high memory when a program adds to the stack. However, when items are removed from the stack, it shrinks upwards from low to high memory.
The assembler reduces the stack pointer(ESP) register by 2, when a word value is pushed on to the stack. On the other hand, the assembler increases the stack pointer by 2 when a word value is popped off.
The assembler decreases or increases the ESP register by 4 when a double word value is pushed or popped off the stack respectively. Therefore the ESP register changes in multiples of 4.