#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Help (Dynamic memory allocation)


    i am beginner in programming. I want to understand dynemic memory allocation function. i search it google but i dont satisified with it... Can anybody plz explain me dynamic memory allocation function.. malloc(),realloc(),calloc() and freee()..


    In school mam do this example ..

    #include<stdio.h>
    #include<conio.h>
    #include<alloc.h>
    #define NULL 0


    void main()
    {
    int *t,*p,size;
    clrscr();


    printf("Enter size");
    scanf("%d",&size);


    t=(int *)malloc(size * sizeof(int));


    if(t==NULL)
    {
    printf("No space available");


    }


    for(p=t;p<=t+size;p++)
    {
    scanf("%d",p);
    }


    printf("Display table value");


    for(p=t+size-1;p>=t;p--)
    {
    printf("%d values at %u address",*p,p);
    }
    getch();
    }

    Plzz explain me this example malloc line..

    Thank you ..

    Plz give me good website for c tutorial :)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    2
    I doubt you'll find someone whose going to give you a detailed explanation about malloc and company. Could you state exactly what your having problems with? Please be specific or Google your general inquires.
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,897
    Rep Power
    481
    After discovering that malloc failed your program must avoid dereferencing the NULL pointer.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo