The function calloc
initializes all the allocated memory to zero.
If you want to initialize all bytes of the memory to a different value, you can use malloc
followed by memset
.
However, in this case, you don't want to initialize all bytes to a same value, so you can't use memset
.
Therefore, it would probably be best to use a loop:
//attempt to allocate memory
myArray = malloc( 102875 * sizeof(int) );
if ( myArray == NULL )
{
fprintf( stderr, "Memory allocation error!\n" );
exit( EXIT_FAILURE );
}
//initialize the memory
for ( size_t i = 0; i < 102875; i++ )
{
myArray[i] = 0xFF;
}