Re: Bytes allocated by the code ??



In article <1164740226.991505.242720@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
onkar <onkar.n.m@xxxxxxxxx> wrote:
how many bytes will be allocted by following code -

#include<stdio.h>
#define MAXROW 3
#define MAXCOL 4
int main(int argc,char **argv){
int (*p)[MAXCOL];
p=(int (*)[MAXCOL])malloc(sizeof(*p)*MAXROW);
printf("%d\n",sizeof(*p));
return 0;
}

The number of bytes required to hold an int or a pointer differ between
platforms, so there isn't just one true correct numeric answer to your
question. Worse yet, different pointers can be different sizes (with
some restrictions) on the same platform -- all that is promised about
pointers to different types is that a void* pointer is the same size as
an unsigned char* pointer.

We could give you a symbolic answer, but not a numeric one.
--
All is vanity. -- Ecclesiastes
.



Relevant Pages

  • Re: Memory Structure Pointer Problems
    ... typedef struct sta { ... char* name; ... int num_cmpnds; ... A pointer to a struct cmp is almost ...
    (comp.lang.c)
  • Re: C# - getting binary data from .lib
    ... Use Marshal.AllocHGlobal to allocate the memory and pass this IntPtr to the ... int retCode = create(id, scale, ptrImage); ... You now control the pointer returned. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Another spinoza challenge
    ... You should test against the int type's limits: ... typedef struct complex ... a pointer to an integer ... A macro is preferable because it is replaced by inline code, ...
    (comp.lang.c)
  • Re: C# - getting binary data from .lib
    ... int create(int id, int scale, unsigned char *image); ... unsigned char* ptrImage = NULL; ... // Read through entire pointer byte by byte and put into managed array ...
    (microsoft.public.dotnet.framework.interop)
  • Re: C# - getting binary data from .lib
    ... then there is a problem with the ptrImage ... int retCode = create(id, scale, ptrImage); ... You now control the pointer returned. ...
    (microsoft.public.dotnet.framework.interop)