malloc

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dasarisrikar
    New Member
    • Sep 2006
    • 18

    malloc

    Hi,
    I hav one doubt....could u pls explainme...
    I hav defined the following code in c

    int **p;
    int *q;
    p=(int *)malloc(sizeof (int *));
    *p=(int *)malloc(sizeof (int));
    **p=12;
    q=*p;
    ....
    what s da sizeof p,*p,**p in bytes..........

    Thanks & Regards.
  • vimase
    New Member
    • Oct 2006
    • 5

    #2
    Originally posted by dasarisrikar
    Hi,
    I hav one doubt....could u pls explainme...
    I hav defined the following code in c

    int **p;
    int *q;
    p=(int *)malloc(sizeof (int *));
    *p=(int *)malloc(sizeof (int));
    **p=12;
    q=*p;
    ....
    what s da sizeof p,*p,**p in bytes..........

    Thanks & Regards.
    First of all you need to allocate memory to p as,
    p = (int **) ....., and not as
    p = (int *).....
    as p is double pointer.

    Regarding the size,
    size of p is 4 bytes,
    size of *p is also 4 bytes, as both are pointers,
    But size of **p is the size of the integer that your hardware supports.

    Comment

    Working...