[ ] num [ ] num [ ] num [ ] num [ ] The above figure clearly shows that, the array num is an integer array with elements. As per the Dev-C++ compiler, bytes are allocated for every int type variable. Here, there are totally elements in the array, where for each element, bytes will be allocated. Totally, bytes will be allocated for this array.
Datatype Turbo C++ Dev C++ char int float long double long double The memory space allocated for an array can be calculated using the following formula: Chapter Page - - Number of bytes allocated for type of array × Number of elements Initialization An array can be initialized at the time of its declaration. Unless an array is initialized, all the array elements contain garbage values. Syntax: <datatype> < > [size] = {value- ,value- ,…………… ,value-n}; Example int age[ ]={ , , , , }; In the above example, the array name is ‘age’ whose size is . In this case, the first element is stored in age[ ], the second element is stored in age[ ] and so on as shown in figure .
int age [ ]={ , , , , }; age [ ] age [ ] age [ ] age [ ] age [ ] Figure . While declaring and initializing values in an array, the values should be given within the curly braces ie. { ….. } The size of an array may be optional when the array is initialized during declaration.
Example: int age[]={ , , , , }; In the above initialization, the size of the array is not specified directly in the declaration with initialization. So, the size is determined by compiler which depends on the total number of values. In this case, the size of the array is five. More examples of array initialization: float x[ ] = { .
}; char vowel[ ] = {'a', 'e', 'i', 'o', 'u', '\ '}; Accepting values to an array