Prepared by Dr Konstantin Degtiarev 12 05 2000
Prepared by Dr. Konstantin Degtiarev, 12. 05. 2000 C Programming Language 1 -dimensional arrays 1 General comments [1] 4 array is a fixed sized group in which the elements are of the same type 4 The general form of array's definition is as follows: type name_of_array[constant_expression] = {initialization_list}; where constant_expression (if present) specifies a size of array (the number of elements in the array) example A: float my_array[10]; typedef is used to assign a new name temp to existing type int; example B: typedef int temp[10]; temp my_array 1, my_array 2; example C: int arr[4] = {1, 10, 20, 30}; example D: int arr[4] = {1, 10}; the initialization list is too short, but still all elements are initialized a presence of [10] means that both declared variables are arrays with 10 elements (all elements are of the type int)
Prepared by Dr. Konstantin Degtiarev, 12. 05. 2000 C Programming Language 1 -dimensional arrays 2 Examples example E: int arr[ ] = {1, 10, 20, 30, 40}; example F: int arr[4] = {1, 10, 20, 30, 40}; array arr[ ] is unsized, but according to the initialization list, C/C++ compiler creates an array (memory storage) of the size which is enough to hold all initial values present compiler complains: "too many initializers" (error message) example G: char arr[8] = {'E', 'x', 'a', 'm', 'p', 'l', 'e', '