What is the difference between these two in terms of memory allocation.
char *p1 = "hello";
char p2[] = "hello";
See Question&Answers more detail:osWhat is the difference between these two in terms of memory allocation.
char *p1 = "hello";
char p2[] = "hello";
See Question&Answers more detail:osThe first one creates a pointer variable (four or eight bytes of storage depending on the platform) and stores a location of a string literal there, The second one creates an array of six characters (including zero string terminator byte) and copies the literal there.
You should get a compiler warning on the first line since the literal is const
.