Is const a compiler level construct ? #include <stdio.h> int main() { const int i = 0; int * p ; p = (int *) & i; *p = 2; printf("(i,p): %x %x \n",&i,p); printf("(i,p): %d %d \n",i,*p); }
I ran this program and got this output.Can somebody explain ? (i,p): bfc3de6c bfc3de6c (i,p): 0 2 On Sat, Aug 20, 2011 at 10:08 AM, sukran dhawan <sukrandha...@gmail.com>wrote: > may be it places the variable in read only memory > > > On Thu, Aug 18, 2011 at 2:38 AM, bihari <kumarvive...@gmail.com> wrote: > >> How to prevent the compiler to alter the value of i in statement: >> const int i=2; >> Just give the idea about the implementation of const int i=somevalue; >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- regards, chinna. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.