RosettaCodeData/Task/Arrays/C/arrays-4.c
Ingy döt Net 80737d5a6a new tasks
2013-04-09 00:46:50 -07:00

11 lines
452 B
C

int numElements = 10;
int *myArray = malloc(sizeof(int) * numElements); /* array of 10 integers */
if ( myArray != NULL ) /* check to ensure allocation succeeded. */
{
/* allocation succeeded */
/* at the end, we need to free the allocated memory */
free(myArray);
}
/* calloc() additionally pre-initializes to all zeros */
short *myShorts = calloc( numElements, sizeof(short)); /* array of 10 */
if (myShorts != NULL)....