lundi 17 avril 2017

Difference between char *ptr and char ptr[ ]

When I try to compile this using clang++:

char *a = "hi";

I get this warning:

ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]

However, when I try to compile this:

char a[] = "hi";

I get no warnings. (except unused variable)

Is there a difference between the two declarations or is it a compiler inaccuracy?

Aucun commentaire:

Enregistrer un commentaire