1

In following code where does 100 in the for loop get stored in the memory of computer?

 #include<stdio.h>

 main()
 {
   int i;
   for(i=0;i<100;i++)
       printf("%d \n",i);
    getchar();
 }
Aditya Hase
  • 113
  • 1
  • 7
Yugesh
  • 59
  • 1
  • 8
  • I'm voting to close this question as off-topic because this is not a question about a programming problem. however cs.stackoverflow.com may be a OK site to ask it on. – Ian Ringrose Apr 26 '16 at 08:12
  • 5
    @IanRingrose How is knowing where things are stored _not_ a programming problem? And how exactly is that a _computer science_ problem? Computer scientists are generally infamous for not knowing how computers work in practice, the question would _definitely_ be off-topic on http://cs.stackexchange.com. – Lundin Apr 26 '16 at 08:15
  • Related to http://stackoverflow.com/q/2589949/694576 and/or http://stackoverflow.com/q/28470295/694576, if not a duplicate. – alk Apr 26 '16 at 08:18
  • The answer to this depends on both the machine architecture and the compiler (and the optimization level). They could be constant operands in machine instructions, or they could be stored in memory and loaded into registers, or they could be dynamically constructed if the bit patterns are simple enough. If it works, then it can be done. – Tom Karzes Apr 26 '16 at 08:22

1 Answers1

4

The C standard doesn't specify where integer constants are stored.

In practice, it will end up in some read-only memory. In this case it will most likely get merged into the actual code memory (.text segment).

Lundin
  • 195,001
  • 40
  • 254
  • 396