What Is an Integer Array?
The so-called array is an ordered sequence of elements. [1] If you name a limited set of variables of the same type, the name is the name of the array. The individual variables that make up an array are called the components of the array, the elements of the array, and sometimes the index variables. The numerical number used to distinguish the individual elements of an array is called a subscript. Array is a form in program design that organizes several elements of the same type in an unordered form for processing convenience. [1] These unordered collections of homogeneous data elements are called arrays.
Array
- In C, arrays [2]
- Declaring a fixed-size array
- There are three ways to declare a fixed-size array, and which method to use depends on the valid range that the array should have:
- (1) Create a public array.
- The general form of initialization assignment is: static type specifier array name [
- 1. The type of the array is actually the value type of the elements of the exponent group. For the same array, the data types of all its elements are the same.
- 2. The rules for writing array names should conform to
- C language provides rich string processing functions, which can be roughly divided into string input, output, merge, modify, compare, convert, copy, search. Using these functions can greatly reduce the burden of programming. String functions used for input and output should include the header file "stdio.h" before use; for other string functions, they should include the header file "string.h".
Several common functions of arrays
- Here are some of the most commonly used string functions:
- 1. String output function puts Format: puts (character array name) Function: Outputs the strings in the character array to the display. I.e. display the string on the screen
#include "stdio.h" main () { static char c [] = "BASIC \ ndBASE"; puts (c); } static char c [] = "BASIC \ ndBASE"; puts (c);
- It can be seen from the program that the escape character can be used in the puts function, so the output is two lines. The puts function can be completely replaced by the printf function. When you need to output in a certain format, the printf function is usually used.
- 2. String input function gets format: gets (character array name) Function: Enter a string from the keyboard of the standard input device. This function gets a function value, which is the first address of the character array.
#include "stdio.h" main () { char st [15]; printf ("input string: \ n"); gets (st); puts (st); }
- It can be seen that when the input string contains spaces, the output is still all strings. Note that the gets function does not end with a space as a string input, but only ends with a carriage return. This is different from the scanf function.
- 3. String connection function strcat format: strcat (character array name 1, character array name 2) Function: connect the character string in character array 2 to the character string in character array 1, and delete the character after string 1. String flag "". The return value of this function is the first address of the character array 1, and the include header file #include "string.h" of the string processing function is required. The program is as follows:
#include "string.h" main () { static char st1 [30] = "My name is"; int st2 [10]; printf ("input your name: \ n"); gets (st2); strcat (st1, st2); puts (st1); } static char st1 [30] = "My name is"; int st2 [10]; printf ("input your name: \ n"); gets (st2); strcat (st1, st2);
- This program concatenates a character array that is initially assigned to a dynamically assigned string. It should be noted that the character array 1 should be defined with a sufficient length, otherwise the entire connected string cannot be loaded.
- 4. String copy function strcpy format: strcpy (character array name 1, character array name 2) Function: Copy the character string in character array 2 to character array 1. The string end flag "" is also copied. The number of characters is 2. It can also be a string constant. This is equivalent to assigning a string to a character array.
#include "string.h" main () { static char st1 [15], st2 [] = "C Language"; strcpy (st1, st2); puts (st1); printf ("\ n"); } static char st1 [15], st2 [] = "C Language"; strcpy (st1, st2);
- This function requires that character array 1 be of sufficient length, otherwise the copied string cannot be fully loaded.
- 5. String comparison function strcmp format: strcmp (character array name 1, character array name 2) Function: Compare the strings in the two arrays in ASCII order, and return the comparison result by the function return value.
- String 1 = string 2, return value = 0;
- String 1> String 2, return value> 0;
- String 1 <String 2, return value <0.
- This function can also be used to compare two string constants, or compare arrays and string constants.
- #include "string.h"
- main ()
- {int k;
- static char st1 [15], st2 [] = "C Language";
- printf ("input a string: \ n");
- gets (st1);
- k = strcmp (st1, st2);
- if (k == 0) printf ("st1 = st2 \ n");
- if (k> 0) printf ("st1> st2 \ n");
- if (k <0) printf ("st1 <st2 \ n");
- }
- {int k;
- static char st1 [15], st2 [] = "C Language";
- printf ("input a string: \ n");
- gets (st1);
- k = strcmp (st1, st2);
- if (k == 0) printf ("st1 = st2 \ n");
- if (k> 0) printf ("st1> st2 \ n");
- if (k <0) printf ("st1 <st2 \ n");
- }
- In this program, the input string is compared with the string in the array st2. The comparison result is returned to k, and the result prompt string is output according to the value of k. When the input is dbase, it can be known from the ASCII code that "dBASE" is greater than "C Language", so k> 0, and the output result is "st1> st2".
- 6. String length measurement function strlen format: strlen (character array name) Function: Measure the actual length of the string (not including the end of string character string) and return the value as a function.
PHP 5 Array PHP 5 Array function
- Function description
- array () Creates an array.
- array_change_key_case () Returns an array whose keys are all uppercase or lowercase.
- array_chunk () splits an array into new array chunks.
- array_column () Returns the value of a single column in the input array.
- array_combine () creates a new array by merging two arrays, an array of key names and an array of key values.
- array_count_values () is used to count the number of occurrences of all values in the array.
- array_diff () Compares arrays and returns the difference between two arrays (only compares key values).
- array_diff_assoc () compares arrays and returns the difference between two arrays (comparing key names and values).
- array_diff_key () compares arrays and returns the difference between two arrays (only compares key names).
- array_diff_uassoc () compares arrays and returns the difference between two arrays (comparing key names and values, using a user-defined key comparison function).
- array_diff_ukey () compares arrays and returns the difference between two arrays (only compare key names, use user-defined key name comparison functions)
- array_fill () Fills an array with the given key values.
- array_fill_keys () Fills an array with the key values given the specified key names.
- array_filter () Filters elements in an array with a callback function.
- array_flip () Inverts / swaps the key names and corresponding associated key values in the array.
- array_intersect () compares arrays and returns the intersection of two arrays (only compares key values).
- array_intersect_assoc () compares arrays and returns the intersection of two arrays (comparing key names and values).
- array_intersect_key () compares arrays and returns the intersection of two arrays (only key names are compared).
- array_intersect_uassoc () compares arrays and returns the intersection of two arrays (comparing key names and values, using a user-defined key comparison function)
- array_intersect_ukey () compares arrays and returns the intersection of two arrays (only compares key names, using a user-defined key name comparison function).
- array_key_exists () Checks if the specified key name exists in the array.
- array_keys () Returns all keys in the array.
- array_map () applies a user-defined function to each value of a given array and returns a new value.
- array_merge () Merges one or more arrays into one.
- array_merge_recursive () Recursively merges one or more arrays into one.
JAVA Eclipse Array Array function of JAVA Eclipse
import java.util.Arrays; // The role of this line is to load the Arrays module
// import java.util.Array.prototype.indexOf public class shuzhu1 { public static void main (String args []) { int [] a = {1,3,6,2,7,9}; System.out.println ("The array before sorting is:"); System.out.println (Arrays.toString (a)); // Call Arrays.toString to convert the value of array a // to a string and display it // call the Array.sort method to sort the array Arrays.sort ( a); System.out .println ("The sorted array is:"); //System.out.println(a+ ""); If this is written, the output will be garbled System.out.println (Arrays.toString (a)); // Call Arrays.toString to array a // Values are converted to strings and displayed