Copy c char pointer to non char pointer

Is there a problem with this?

char* field = new char[2];
field[0] = 'S';
field[1] = '\0';

char c = *field;

will always be equal to 's'?

+3
source share
4 answers

No problem with that, c will always be "S".

+4
source

This is perfectly normal - and c will always be equal to "S". Highlighting fielda type pointer charwill result in char.

+2
source

The problem is that new char[2]C is not syntax. However, the general idea is correct: cthere will always be an "S".

0
source

There is nothing wrong. When you look for a field array in a string

char c = *field;

what you are actually requesting is the value of the first element of the array, in this case "S".

0
source

All Articles