Wednesday, July 22, 2015

Dynamic Memory Allocation - A simple example

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *data;
    printf("hit enter to create memory");
    getch();
    data=(int*)malloc(sizeof(int));

    if(data==NULL)
    {
        printf("\nError! memory not allocated.");
        exit(0);
    }
    printf("\nEnter data to store: ");
    scanf("%d",data);
    printf("data stored is =%d",*data);

    return 0;
}

No comments:

Post a Comment