Instruction
1
Null array in C/C++. When you initialize an array in the languages C and C++ array elements is assigned a random value, in difference, for example from languages like C# or Java. So hope that all elements will be equal to the specified value, is not necessary. For languages With and With++ there are several ways to reset the arrays. To do this, when it is created, use the following code: int array[10000];memset(array,0,10000);This code will create an array with 10000 elements and assigns each element a value of 0. Also, to create an array of zeros at initialization, use the more simple code: int array[100]={0};This code will create an array size of 100 elements and assign all elements set to 0. To reset the array, use for loops:i=0;for( i ; i < N ; i++ ) //where N is the size of the array{ array [ i ] = 0 ; //where array is the name of the array} This code iterates over the elements of the array from the first element to element number N, and assigns each element a value of 0. If you are using Visual C++ use the function ZeroMemory(). If you want to reset a string (string in C/C++ is a character array), you can just zero out the first element and the rest in the future will not be used.
2
Null array in Java. Unlike C/C++ in Java when you initialize an array as a class variable, all elements are assigned the value equal to 0 - if it is an array, false if it is an array of Booleans, null - if it is an array of objects. Therefore, in Java, is not necessary to manually reset the array when initializing. But, if you create the array as a class variable, and declare it in the function body or loop, the compiler does not guarantee that all values will be 0 (false, null). In this case, to reset the array, use the following loop:int array[] = new int[10000]; //create an array with 10000 элементовfor(int i = 0 ; i < array.length ; i++ ) { //loop through all array elements array[i] = 0 ; //assign each array value to 0}