Question

Explain how to double the capacity of a static array declared as int a[100];

Explain how to double the capacity of a static array declared as int a[100];

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// create a new double sized array
int *copy = new int[200];
// copy all elements from a to copy
for (int i = 0; i < 100; ++i) {
    copy[i] = a[i];
}
// assign a to this newly created array
a = copy;



Add a comment
Know the answer?
Add Answer to:
Explain how to double the capacity of a static array declared as int a[100];
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index...

    Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens? Show the code. An array of 1000 integers is declared. What is the largest integer that can be used as an index to the array? Shows the code. Consider the declaration: int v[1]; What is the index of the last element of this array? Declare an array named a of 10 int elements and initialize the elements (starting with the first) to the...

  • Assume an array list is declared as follows: int list[100] and that all other variables have...

    Assume an array list is declared as follows: int list[100] and that all other variables have been appropriately declared. Tell whether each of the following is a valid or invalid statement. If not valid explain why not. cin>>list[3]; cout<<list; x = list[3]+list[4]; list[10] = 3.2; cout<<list[3, 5, 22]; for (int i = 0; i < 100; i ++) cout<<list[i];

  • Which two code fragments correctly create and initialize a static array of int elements? (Choose two.) A. static final intl] a100,200 B. static final int[l a; static { a=new int[2]; a[01-100; a[1]=20...

    Which two code fragments correctly create and initialize a static array of int elements? (Choose two.) A. static final intl] a100,200 B. static final int[l a; static { a=new int[2]; a[01-100; a[1]=200; } C. static final int[] a = new int[2]{ 100,200 }; D. static final intl a static void init() ( a new int[3] a[o] 100; a[11 200; Which two code fragments correctly create and initialize a static array of int elements? (Choose two.) A. static final intl] a100,200...

  • 3. Suppose that an array of size 5 is declared, of type integer (4 bytes). int...

    3. Suppose that an array of size 5 is declared, of type integer (4 bytes). int theArray[5]; Also, suppose that the computer assigns the memory address 3152 to the variable at index 0. Explain how the computer would access theArray[2], and what the memory address would be. Draw diagrams as necessary. Following are example question and answer: Suppose that an array of size 5 is declared, of type double (8 bytes). double theArray[5]; Also, suppose that the computer assigns the...

  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array...

    Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...

  • Given the prototype: int countPassing(double arr[], int num); Assume that array arr contains num elements with...

    Given the prototype: int countPassing(double arr[], int num); Assume that array arr contains num elements with a value. You may assume that the array has been declared with at least num elements. Write the the function definition including the function header for countPassing() so that the number of values greater than or equal to 69.5 in arr[] is returned.

  • 1. Write a complete program based on public static int lastIndexOf (int[] array, int value) {...

    1. Write a complete program based on public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >= 0; i--) { if (array [i] == value) { return i; } } return -1; write a method called lastindexof that accepts an array of integers and an integer value as its parameters and returns the last index at which the value occurs in the array. the method should return -1 if the value is...

  • Develop a set of static methods in a class called Array Tools that perform the functions...

    Develop a set of static methods in a class called Array Tools that perform the functions below, and overload the methods for the specified types: Description Returns the minimum value stored in an array. Array Tools Method char minimum char array[]) int minimum( int array[] ) double minimum double arrayll ) char maximum char array() ) int maximum( int array[] ) double maximum( double array[] ) Returns the maximum value stored in an array. int minimumAt( char array()) int minimumAt(...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT