I am stuck with basics of an array. I googled it, but I could not able to solve this. This question is concept oriented, but I am not able to bridge a gap. Please help me out resolve this.
I am very clear on initializing array for the first time, but not able to clear the array for next time :-( :-(
int myArray[10] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; // All elements of myArray are 5
int myArray[10] = { 0 }; // Will initialize all elements to 0
int myArray[10] = { 5 }; // Will initialize myArray[0] to 5 and other elements to 0
static int myArray[10]; // Will initialize all elements to 0
int myArray[10];// This will declare and define (allocate memory) but won’t initialize
int i; // Loop variable
for (i = 0; i < 10; ++i) // Using for loop we are initializing
{
myArray[i] = 5;
}
Problem statement:
I am using a Global array which is of size 10000. I have 1k iteration loop, where I have to set the array to 'Zero' or predefined value i.e., 5 for each iteration.
I am doing this at the end of interaction like this:
myArray[10000] = { 0 };
Its giving error while compiling in GCC compiler.
error: [11707] syntax error before '{' token
Please help me out resolve this.
Thanks in advance.
memset()for you? ...memset()won't able to set each values to 5.