Simple C language dynamic allocation of memory - adapted from c primer plus

// dynamic memory allocation Demo 
#include <stdio.h> 
#include <stdlib.h>

    int main(void)
    {
        you * PTD;
        you max;
        you number;
        you i = 0 ;

        the puts ( " Enter the length of the integer you want to enter ." );

        if (scanf("%d",&max)!=1)
        {
            the puts ( " erroneous input, retry again " );
            exit(EXIT_FAILURE);
        }
        // allocate memory 
        PTD = ( int *) the malloc (max * the sizeof ( int ));

        if (ptd==NULL)
        {
            the puts ( " memory full " );
            exit(EXIT_FAILURE);
        }
        
        puts("请输入数字");
        while (i<max && scanf("%d",&ptd[i])==1)
        {
            ++i;
        }
        for ( i = 0; i < max; i++)
        {
            printf("%d ",ptd[i]);
        }
        // free the memory 
        as Free (PTD);

        
        return 0;
    }

This is a water paste, recorded at entry C language of their own end.

Guess you like

Origin www.cnblogs.com/L-white/p/11985446.html