Use char[] or char* to initialize a string?

Asked

Viewed 23 times

0

It would be more correct to use like this:

char[] nome = "Fulano";

Or so:

char* nome = "Fulano";

I’ve even seen cases of starting a string like this:

char nome[256];
strcpy(&nome, "Fulano");

Or so:

char *nome;
strcpy(nome, "Fulano");

Are there differences between these options? If so, which ones? What is the most recommended and safe? What is the most recommended for certain situations? And finally, why use the strcpy() to initialize a string if you can initialize using the operator = logo in variable declaration?

  • https://answall.com/q/160692/101 and https://answall.com/q/136628/101 (it’s actually full of questions on the subject)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.