UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » two memory problem

#1 2007-09-10 02:08 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: two memory problem

void GetMemory2(char **p,int num)
{
*p=(char*)malloc(num);


}
void Test(void)
{
   char *str=NULL;
  GetMemory2(&str,100);
strcpy(str,"hello");
printf(str);
}

when I execute the Test,what result can happen?

char *GetMemory(void)
{char[]="hello world";
return p;
}
void Test(void)
{char *str=NULL;
str=GetMemory();
printf(str);
}

when I execute this Test,what result?


and I also have an alignment question:
   for example:

struct {
   long a1;
  short a2;

}A

sizeof(A)=?

struct {
short a1;
short a2;
short a3;


}B

sizeof(B)=?
whether sizeof(A) equals sizeof(B)?
can you give me some explanations about above questions.

thanks.

Offline

#2 2007-09-10 12:53 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: two memory problem

Offline

  • Index
  • » C
  • » two memory problem

Board footer

Powered by FluxBB