1

I have a question in mind : earlier I disassembled a simple program with a :

char *tab = "hello";

And I saw that unlike array, only the address of the string is pushed onto the stack. So I was wondering where is the content of the string stored then ?

user3102158
  • 173
  • 9

1 Answers1

0

The string "hello" is, of course, static data that is included in your executable, verbatim. This data is already available in memory when your program runs, all static and constant data is. And since you only use its address, only that address is pushed onto the stack.

Now, if you create an array like this:

char tab[] = "hello";

you tell the compiler that you want to create an array on the stack, an array which you may freely store anything into you like. And you tell the compiler to initialize that array with the constant static string "hello", so it copies the data from the static storage to the array on the stack.

cmaster - reinstate monica
  • 38,891
  • 9
  • 62
  • 106