copying c char pointer to a non pointer char
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'?
No problem with that, c will always be 'S'.
This is totally fine - and c will always be equal to 'S'. Dereferencing field
, a pointer of type char
will result in a char
.
There is a problem in that new char[2]
is not C syntax. The general idea is correct, though: c
will always be 'S'.
There's nothing wrong with that. When you dereference the field array in the line
char c = *field;
what you're actually asking is for the value of the first element of the array, in this case 'S'.
精彩评论