& str,str之间的C指针和malloc混淆

时间:2016-01-16 06:48:27

标签: malloc

我是C的初学者,在下面的代码中,当它被转换为整数时,& str和str的输出值是什么。

int main()
{
   char *str;

   /* Initial memory allocation */

   str = (char *) malloc(15);

   strcpy(str, "Hello");

   printf("String = %s,  Address = %d ,val=%d\n", str, &str,str);


   free(str);

   return(0);
}

这是我得到的输出:

String = Hello,Address = -1407247144,val = 22335504

0 个答案:

没有答案