c++ 指针的问题怎么解决

char tio = "456700890";
int hao[]= { 1,2,3,4,5 };
int *h = hao;
int
* f = &h;
printf("%d\n", h);
puts(tio);
我想知道输出的h和tio的值是怎么得出的 还有puts(tio)而tio是一个指针输出一个tio怎么就等于456700890

是不是应该char *tio = "456700890";
puts(tio);是将该字符串打印出来。

printf("%d\n", h);是指针指向的地址。

 int main()
{
    char tio[] = "456700890";
    int hao[] = { 1,2,3,4,5 };
    int *h = hao;
    int* f = h;
    printf("%d\n", *h);//1,如果输出h则是hao数组的首地址
    puts(tio);//456700890,puts将字符数组tio以字符串输出
    return 0;
}

puts是一个函数,从此地址开始,一直输出。
char *tio = "456700890";

 puts本身接收一个char *或者数组,可以输出一个字符串。遇到\\0结束输出
而你char tio = "456700890";其实是溢出了,因为tio只能放一个字符,所以不可能装下\\0,puts输出会导致段错误。(segmentfault)
int* f = &h;,而h是hao[]的首地址,因此f是地址的地址,这个输出结果不同的机器不同
第一行修改为char* tio = "456700890";可以通过编译
在线运行如下
http://codepad.org/7wunTKGn



int main()
{
char* tio = "456700890";
int hao[]= { 1,2,3,4,5 };
int h = hao;
int
f = &h;
printf("%d\n", h);
puts(tio);
}


-1276276
456700890