0

Is there a difference between:

char string = "name";
const char* point = string;

vs

const char string[] = "name";

Will you please explain the difference too?

user1334858
  • 1,885
  • 5
  • 30
  • 39

1 Answers1

5

Yes.

The first simply points to a read only section of memory, the declaration really should be:

const char* string = "name";

The second creates an array long enough to hold the string "name" (so, four characters plus one for the null terminator) and copies the string inside the allocated space.

Nik Bougalis
  • 10,495
  • 1
  • 21
  • 37
Collin
  • 11,977
  • 2
  • 46
  • 60