将 c char 指针复制到非指针 char
这样做有什么问题吗?
char* field = new char[2];
field[0] = 'S';
field[1] = '\0';
char c = *field;
c 总是等于 'S' 吗?
Is there any problem on doing that?
char* field = new char[2];
field[0] = 'S';
field[1] = '\0';
char c = *field;
will c always be equal to 'S'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
没问题,c 永远是“S”。
No problem with that, c will always be 'S'.
这完全没问题 - 并且 c 将始终等于“S”。取消引用
field
,char
类型的指针将产生char
。This is totally fine - and c will always be equal to 'S'. Dereferencing
field
, a pointer of typechar
will result in achar
.有一个问题是
new char[2]
不是 C 语法。不过,总体思路是正确的:c
始终是“S”。There is a problem in that
new char[2]
is not C syntax. The general idea is correct, though:c
will always be 'S'.这没有什么问题。当您取消引用该行中的字段数组时,
您实际上要求的是数组第一个元素的值,在本例中为“S”。
There's nothing wrong with that. When you dereference the field array in the line
what you're actually asking is for the value of the first element of the array, in this case 'S'.