Concept explainers
Array:
An array is defined as a group that consists of similar data types, but the size of array can also declared which indicates that the number of values an array can hold and it is always indexed, starting from 0.
Declaration of an array variable:
- • An array variable is declared with “[]” after the data type.
- • The following is the syntax for declaring an array variable.
dataType[] arrayVar;
or
dataType arrayVar[];
- • Both the above given statements can be used, but the former one is mostly used.
- • The element type can be any data type and the same data type must be used by all the elements.
Array initialization:
Array declaration does not initialize the array in memory location. So, we can assign the values to that particular array.
The sequence of values within the braces and separated with commas is referred as an initialization list.
The array can be initialized in initialization list by group of array element is given below:
const int size= 3;
int[] arrayVar = new int[size]{1, 2, 3};
The array can be initialized without size declaratory in initialization list is given below:
int[] arrayVar = new int[]{1, 2, 3};
The array can be initialized without new operator in initialization is given below:
int[] arrayVar = {1, 2, 3};
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting out with Visual C# (4th Edition)
- Write a statement that updates the second element in the intOrders array by the value stored in the intSold variable.arrow_forwardIs this statement true or false? The subscript of the last element is always one less than the length of the array specified by the Length property.arrow_forwardCreate a statement that assigns the intLastSub variable the highest subscript in the intOrders array.arrow_forward
- Which of the following declares a four-element one-dimensional array?a. Dim strLetters() As String = "A", "B", "C", "D"b. Dim strLetters(3) As String = {"A", "B", "C", "D"}c. Dim strLetters(3) As Stringd. both b and carrow_forwardWrite a statement that declares a jagged array of int values and initialize the columns of each row with the values in the following table of data:arrow_forwardWhich of the following statement will display elements of the array in one line at a time? char myArray[4] = {'a', 'b', 'c', 'd'}; for (int i = 0; i < 4; i += 1) ---- code goes here ---- cout >> myArray >> endl; cout >> myArray[i] >> endl; cout << myArray[i] << endl; cout << myArray[4] << endl;arrow_forward
- Create a procedure that generates a random string of length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer to an array of bytes that will hold the random string. Write a test program that calls your procedure 20 times and displays the strings in the console window. Sample Output:arrow_forwardBelow you will find code blocks necessary to insert a value into an ordered array given a position (index) to insert. Be careful! Some lines are not needed.arrow_forwardWrite a statement that assigns the length of an array named intHomework to intGrade.arrow_forward
- A personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries. Use the following names and phone numbers: Name Phone # Gina (847) 341-0912 Marcia (847) 341-2392 Rita (847) 354-0654 Jennifer (414) 234-0912 Fred (414) 435-6567 Neil (608) 123-0904 Judy (608) 435-0434 Arlene (608) 123-0312 LaWanda (920) 787-9813 Deepak (930) 412-0991arrow_forwardA personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries. Using Scanner.input to prompt user, Use the following names and phone numbers: Gina (847) 341-0912 Marcia (847) 341-2392 Rita (847) 354-0654 Jennifer (414) 234-0912 Fred (414) 435-6567 Neil (608) 123-0904 Judy (608) 435-0434 Arlene (608) 123-0312 LaWanda (920) 787-9813 Deepak (930) 412-0991arrow_forwardA personal phone directory contains room for first names and phone numbers for 30 people. Assign names and phone numbers for the first 10 people. Prompt the user for a name, and if the name is found in the list, display the corresponding phone number. If the name is not found in the list, prompt the user for a phone number, and add the new name and phone number to the list. Continue to prompt the user for names until the user enters quit. After the arrays are full (containing 30 names), do not allow the user to add new entries. Use the following names and phone numbers:arrow_forward
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT