Answer:
Option 1: May crash at runtime because it can input more elements than the array can hold
Explanation:
Given the code as follows:
- int[] a = {1, 3, 7, 0, 0, 0};
- int size = 3, capacity = 6;
- int value = cin.nextInt();
- while (value > 0)
- {
- a[size] = value;
- size++;
- value = cin.nextInt();
- }
From the code above, we know the <em>a</em> is an array with six elements (Line 1). Since the array has been initialized with six elements, the capacity of the array cannot be altered in later stage.
However, a while loop is created to keep prompting for user input an integer and overwrite the value in the array started from index 3 (Line 4- 9). In every round of loop, the index is incremented by 1 (Line 7). If the user input for variable <em>value</em> is always above zero, the while loop will persist. This may reach a point where the index value is out of bound and crash the program. Please note the maximum index value for the array is supposedly be 5.
Answer:
See explaination
Explanation:
java code:
class DONALD
{
static class Node
{
int data;
Node next;
}
static Node head=null;
static int largestElement(Node head)
{
Int max=Integer.MIN_VALUE;
while(head!=null)
{
if(max<head.data)
max=head.data;
head=head.next;
}
return max;
}
static int smallestElement(Node head)
{
int min=Integer.MAX_VALUE;
while(head!=null)
{
if(min>head.data)
min=head.data;
head=head.next;
}
return min;
}
static void push(int data)
{
Node newNode=new Node();
newNode.data= data;
newNode.next=(head);
(head)=newNode;
}
static void printList(Node head)
{
while(head!=null)
{
System.out.println(head.data + " -> ");
head=head.next;
}
System.out.println("NULL");
}
public static void main(String[] args)
push(15);
push(14);
push(13);
push(22);
push(17);
System.out.println("Linked list is : ");
printList(head);
System.out.println("Maximum element in linked list: ");
System.out.println(largestelement(head));
System.out.print("Maximum element in Linked List: " );
System.out.print(smallestElement(head));
}
}
The CPU performs the instructions and writes the data back into your computer's random access memory or RAM. RAM temporarily stores data while your computer is running.
ASCII is an agreement on which number represents which typographic character. Using this table you can look up the number of any character. For instance, "A" has 65, but that is a decimal. Next step is to represent this decimal number in hexadecimal. You can do that by taking the divisor and remainder of a division by 16. Numbers beyond 9 are represented as a through f. Hexadecimal numbers are commonly prefixed by "0x" to make them recognizable.
So "A" = 65 = 4*16+1 = 0x41
And "Z" = 90 = 5*16+10 = 0x5a
There are ASCII tables that have the hexadecimal value in them, to make the task easier (www.asciitable.com).
If you want to do this programmatically, you can write something like this (node.js):
console.log( Buffer.from('AZ', 'utf8').toString('hex'));
Note that the 0x prefix is not shown here.