Hi all,
If I have a piece of code something like this
void main(void)
{
char * p1="abcdefghijk lmn";
............... ............... ...............
}
For p1 and whatever it points to , where is the memory allocated. Is
it on heap or stack or
some other common global area. I am assuming it should be either on
stack or some global area. Unless
a user does a malloc storage space cannot be allocated on heap is my
assumption. Can someone
throw some light on how compilers do this.
What if the above piece of code is changed to something like
void main(void)
{
char *p1;
char a[20]="abcdefgh";
strcpy(p1,a);
}
Now where is the space allocated for p1 and whatever it points to
after strcpy.
Thanks in advance.
Regards,
Ar
If I have a piece of code something like this
void main(void)
{
char * p1="abcdefghijk lmn";
............... ............... ...............
}
For p1 and whatever it points to , where is the memory allocated. Is
it on heap or stack or
some other common global area. I am assuming it should be either on
stack or some global area. Unless
a user does a malloc storage space cannot be allocated on heap is my
assumption. Can someone
throw some light on how compilers do this.
What if the above piece of code is changed to something like
void main(void)
{
char *p1;
char a[20]="abcdefgh";
strcpy(p1,a);
}
Now where is the space allocated for p1 and whatever it points to
after strcpy.
Thanks in advance.
Regards,
Ar
Comment