您的位置:首页 > 其它

关于string的一点思考

2011-08-03 21:15 337 查看
string str("hello");
	const char *p = str.c_str();
	char *pp = &str[0];
	unsigned int num = (unsigned int)p;
	cout << "0x" <<hex << num << endl;
	num = ( unsigned int )pp;
	cout << "0x" <<hex << num << endl;
	cout << &str[0] << endl;
	cout << &str << endl;

其实指针p和指针pp的地址是一样的,但是&str和p和pp的值是不一样的,不妨这么理解,因为&str是取string这个类的地址,而p和pp都是取的string定义的字符串的第一个元素的地址,
所以&str和p以及pp是不一样的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: