Character Array vs String Constant Pointers

C
Author

Imad Dabbura

Published

September 30, 2022

In C, there is two ways to define a string:

  1. Define it as an array of character such as:
char aname[] = "Imad";
  1. Or define it as a pointer to string constant such as:
char *pname = "Imad";

They are almost identical except for 1 subtle difference: