2. References to one-dimensional arrays:
Array name [subscript];
3. Initialization of one-dimensional arrays:
A. Assigning an initial value to an array element when it is defined;
B. You can assign values to only a subset of the elements;
C. To make an array of all elements of the value of 0, can be written as: a[10]={0};
Be aware of int a[10] = {1}; Do not initialize the array to full 1, just initialize the first bit to 1, followed by all 0 drops.
D. When assigning initial values to all array elements, you can specify no array length.
Two, 1. Definition of two-D arrays:
Type specifier array name [constant expression] [constant expression];
2. References to two-D arrays:
Array name [subscript] [subscript];
3. Initialization of two-D arrays:
A. Branches assign values to two-dimensional arrays. int a[3][4]={{1,2,3,4},{5,6,7,8},{,9,10,11,12}};
B. You can write all the data in a curly bracket, assigning an initial value to each element in the order in which it is arranged.
C. You can assign an initial value to some elements:
D. If all elements are assigned an initial value (that is, providing all initial data), the length of the first dimension may not be specified when the array is defined, but the length of the second dimension cannot be saved.
Iii. 1. Character array definition: Reference one-dimensional array definition, type change.
2. Initialization of character arrays: refer to one-dimensional array initialization.
3. Reference to a character array: reference to a one-dimensional array.
4. String and end-of-string flag: String encountered ' \ ', indicating the end of the string.
5. Input and output of character array:
A. Enter output by character, using "%c";
B. Enter the entire string one at a time with "%s".
Note: The output character does not include the Terminator ' s '; B. When you output a string with '%s ', the input entry in the printf function is a character array name, not an array element name. C. If the length of the array is greater than the actual length of the string, it will only output to '/'. D. If a character array contains more than one ' s ', the output ends when the first '. ' Is encountered.
6. String handling functions:
A.puts (character array) function: Outputs a string (a sequence of characters ending with ' \ s ') to the terminal.
B.gets (character array) function: Enter a string into a character array with a terminal, and get a function value. The function value is the starting address of the character array.
Note: The putshe gets function can only enter or output a string, and cannot be written as puts (STR1,STR2) or gets (STR1,STR2).
C.strcat (character array 1, character array 2) Acts: Concatenate strings in two character arrays, string 2 to the back of the string 1, the result is placed in the character array 1, after the function call to get a function value-the address of the character array 1.
Description: A. Character array 1 must be large enough to accommodate the new string after the connection. B. The connection Qian Liang string is followed by a ' + ', the connection will be after the string 1 ' \ ' is canceled, only the new string at the end of a '.
d.strcpy (character array 1, string 2) Acts: is to copy the string 2 into the character array 1.
Description: A. Character array 1 must be defined sufficiently large to accommodate the copied string, and the length of the character array 1 should not be less than the length of the string 2. B. " The character array 1 "must be written as an array name," String 2 "can be a character array name, or it can be a string constant. C. Copy to the character array 1 along with the ' + ' after the string. D. You cannot use an assignment statement to give a string constant or an array of characters directly to an array of characters. E. You can use the strcpy function to copy the first number of characters in string 2 to the character array 1. such as: strcpy (str1,str2,2);
E.STRCMP (String 1, String 2) Acts: is the comparison between string 1 and string 2.
Description: A. If string 1 = string 2, the function value is 0. B. If the string 1> string 2, the function value is a positive integer. C. If the string 1< string 2, the function value must be negative. Note: Comparisons of two strings can only take the form of strcmp (string 1, String 2) and cannot be used in other forms.
F.strlen (character array): A function that tests the length of a string, and the value of the function is the actual length in the string, not including '. '
G.STRLWR (String) function: Converts uppercase letters in a string to lowercase.
H.STRUPR (String): Converts the lowercase letter of a string into uppercase letters.
Definition and use of arrays