Malloc dynamically allocates memory and malloc dynamically allocates memory.
I haven't studied C for a long time. After reviewing it, sometimes I feel that C is very elegant, and I want to learn the best choice of algorithms and data structures.
# Include "stdafx. h "# include <stdlib. h> int main () {int arr [5] = {1, 2, 3, 4, 5}; int len; printf ("Enter the array length len = "); scanf_s ("% d", & len); int * pArr = (int *) malloc (sizeof (int) * len); // 1. apply for 20 bytes of memory for read/write. // 2. the malloc function returns only the first byte address, all of which must be forcibly converted to int * // * pArr = 4; // similar to arr [0] = 4; // pArr [1] = 3; // similar to arr [1] = 3; printf ("Enter % d numbers \ r \ n", len ); for (int I = 0; I <len; I ++) {scanf_s ("% d", & pArr [I]);} printf ("the five numbers you entered are \ r \ n"); for (int j = 0; j <len; j ++) {printf ("% d \ r \ n", * (pArr + j);} free (pArr); // release the applied memory return 0 ;}