0

is

char* array[] = {"first","second","other one","last"};

an array of char* ?

the strings (array[0],...) can not be modified even with a cast to char*. where is the string putten on memory ?

can not be modified = "array[0][0] = 'a'"; does not work.

3
  • 1
    "where is the string putten on memory" is just wrong. A cast doesn't touch the memory, it just tells the compiler to interpret a variable in a certain way. Commented Nov 9, 2011 at 7:45
  • Possible duplicate of: stackoverflow.com/questions/349025/… Commented Nov 9, 2011 at 7:47
  • ThiefMaster : you misunderstood. i said where in memory refering to in what memory : not stack, is it data memory, somewhere special on the heap ? it could help me to understand the work of the compiler. Commented Nov 9, 2011 at 13:19

2 Answers 2

2

It is an array of char* but you have initialized it with string literals. These are read-only and attempting to modify them is undefined behaviour.

It is common for a compiler to store literals in a read-only segment of the executable image which is probably why you are seeing segmentation faults when you attempt to modify the contents.

Sign up to request clarification or add additional context in comments.

Comments

2

Your strings are of type const char * and can be stored in ROM. Pointers to those locations are stored in the array.

2 Comments

is that related to BIOS? One is RAM and other one is ROM.
@user974191: I do not quite understand your question. On a PC and similar systems, everything is stored in RAM (for normal programs). But for embedded systems, the compiler can use ROM-segments to store the code. Programming a BIOS is similar to creating an embedded system, and also identifies ROM and RAM areas. When using modern PCs, the code sections, even when stored in RAM, can be protected by the OS in combination with the processor to protect the memory segment and effectively create a read-only segment for the program code and/or read-only data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.