所以我有以下代码:C++:指针输出困惑我
cout << _userLoginName << endl;
cout << *_userLoginName << endl;
cout << (_userLoginName+1) << endl;
cout << *(_userLoginName+1) << endl;
可变char * _userLoginName
已被设置等于"smith"
。我的问题很简单:为什么在最后几行代码中我会得到以下输出?
smith // as from cout << _userLoginName << endl;
s // as from cout << *_userLoginName << endl;
mith // cout << (_userLoginName+1) << endl;
m // cout << *(_userLoginName+1) << endl;
我真的尝试推理结果,但我无法弄清楚。 谢谢。
如何打印实际值然后(参数的地址)? – Yokhen 2012-02-01 00:11:50
@Yokhen:要打印地址,您通常可以使用类似'cout << static_cast(_userLoginName)'的方式逃脱。 –
2012-02-01 00:12:41