main() { // wrong. Should return int
int main() { // better
int *a-ptr = //wrong. no dashes in variable names
int *a_ptr = // better, use underscores if you want to have multiparted names
(int *)malloc(int); // wrong. Don't typecast the return of malloc(), also it takes a
// size, not a type
malloc(sizeof(int)); // better, you want enought memory for the sizeof 1 int
したがって、コードのより良いバージョンは次のようになります。
int main() {
int *a_ptr = malloc(sizeof(int));
*a_ptr = 5;
printf("%d", *a_ptr);
free(a_ptr); // When you're done using memory allocated with malloc, free it
return 0;
}