C
variantArray
호타리
2023. 9. 1. 13:59
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int size;
scanf("%d", &size);
//int array[size]; // ???
int *pArr = malloc(sizeof(int) * size);
if (pArr == NULL)
{
fprintf(stderr, "can't malloc()\n");
exit(1);
}
for (int i = 0; i < size; ++i)
{
pArr[i] = i + 1;
}
for (int i = 0; i < size; ++i)
{
printf("%d\n", pArr[i]);
}
free(pArr);
return 0;
}
<compile 결과>