Where does read only memory exist in code after compilation [duplicate] - c

This question already has answers here:
String literals: Where do they go?
(8 answers)
Closed 9 years ago.
char *token = "some random string";
When I declare this, I know "some random string" is stored in read-only memory. My question is where will read-only memory be? Will it be in the data section or in bss?

It will be in the data section, BSS is for non-initialized memory.
If using GNU binutils, you can use nm to list the contents of an executable and see in which sections various symbols reside.

Related

Clearing memory allocated to a string in C? [duplicate]

This question already has answers here:
Is a string literal in С++ created in static memory?
(4 answers)
Where are static variables stored in C and C++?
(16 answers)
Closed 7 years ago.
How does memory gets allocated for a string literal in C and do we need to free it?
E.g.:
char *k="hello world";
Where does this string get stored and how does it get de-allocated?
where does this string get stored
Usually in read-only memory, you cannot modify it. In gcc, on most systems, they are located in the .TEXT section.
how does it get de-allocated
upon program termination.

How does memory gets allocated for string literal in c and do we need to free it? [duplicate]

This question already has answers here:
Is a string literal in С++ created in static memory?
(4 answers)
Where are static variables stored in C and C++?
(16 answers)
Closed 7 years ago.
How does memory gets allocated for a string literal in C and do we need to free it?
E.g.:
char *k="hello world";
Where does this string get stored and how does it get de-allocated?
where does this string get stored
Usually in read-only memory, you cannot modify it. In gcc, on most systems, they are located in the .TEXT section.
how does it get de-allocated
upon program termination.

Store data to a memory location in C [duplicate]

This question already has answers here:
How can I store a value at a specific location in the memory?
(4 answers)
Closed 8 years ago.
Is is possible to directly store data into a memory location using C ?
To be more specific,
What if i want to store an integer data to a memory location starting from 00100000. Is it possible ?
Yes it is. You can do this: int*ptr = 00100000; And then do *(ptr) = 10; I highly recommend you don't do this however.

What section of memory are static local constants stored in? [duplicate]

This question already has answers here:
Where are static variables stored in C and C++?
(16 answers)
Closed 9 years ago.
I know global constant will be stored in "Read Only" section. But What section of memory are static local constants stored in?
It depends on the compiler and the platform you're compiling for. They may be placed on the bottom of the stack, in the data segment of the primary thread, or simply on the heap, or even somewhere else.

how to get the memory access type in C/C++ in Linux [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a better way than parsing /proc/self/maps to figure out memory protection?
I have a pointer and I want to check if the referenced memory is readable, writeable and/or executable. How can I do this?
You will have to parse the file /proc/self/maps which contains memory mappings of your process, and check which of the mappings lie within the value of your pointer (if any). The /proc/self/maps file contains the memory protection (read/write/execute).
See this question for more info about the maps file.

Resources