----- Original Message ----- From: "suganthi rams" <ashvinistar@yahoo.co.in> To: <C-Guru@yahoogroups.com> Sent: Friday, April 23, 2004 9:36 AM Subject: [C-Guru] reg printf > hi all, > > in below code > > main() > { > printf("HELLO WORLD\n"); > } > > in which area of memory the string in printf is stored? Your question, in general, is about storage of string literals. The answer varies under the following situations: * The Standard recommends the string literal to be a read-only; thus, allows sharing copies of string with identical text. In this case, the implementation may store the sting in the code section, or any other read-only section. This method helps perform some optimizations. * Many implementation provide extensions which are, generally, non portable. One such extension is writable string literals. The string is, then, stored in the program's static region. Thus, there would be different copies of string literal of identical text. Many compilers provide option to control the behaviour of character string literals. For example, GCC provide a compiler switch, -fwritable-strings, to store strings in writable data section. By default, GCC merges duplicate strings, whereas, Borland's Turbo C/C++ doesn't. It provides the following switches: -d merge duplicate string on -d- merge duplicate string off Many compilers provide pragmas to control, but these are non portable. The Standard specifies only few pragmas that are portable, and is out of scope here. Lastly, it is best practice to define main() as: #include <stdlib.h> int main ( void ) { /* .. */ return EXIT_SUCCESS; }