0

When we declare a variable as

char arr[] = "Hello";

then the string "Hello" above is located in stack.

But when we declare a variable as

char* arr = "Hello";

then the string "Hello" is declared in stack or code segment? If code segment then why code segment and not in stack?

RKum
  • 758
  • 2
  • 12
  • 33

1 Answers1

1

No. The string literal is not declared in any segment.

It's got static storage duration and it's read-only.

Because it's read-only, assigning its address to a char* is incorrect. Change it to char const* arr = "...";

MSalters
  • 173,980
  • 10
  • 155
  • 350