Computing.Net > Forums > Programming > any way to chane the val of const ??

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

any way to chane the val of const ??

Reply to Message Icon

Name: Adnan
Date: March 9, 2002 at 07:57:07 Pacific
Comment:

hi
is there any way to change the value of a constant integer in c++;

constant int a=10;

i need to chande its value is there any algotithm?

plz... tell me



Sponsored Link
Ads by Google

Response Number 1
Name: dale
Date: March 9, 2002 at 08:56:39 Pacific
Reply:

not that i know of, but there may be...seems to me it wouldn't be a constant then though..... :P Maybe if you can say why you want to change it, we can help you think of some kind of workaround
-Dale


0

Response Number 2
Name: Mr. A
Date: March 9, 2002 at 13:56:24 Pacific
Reply:

In some implemantations of C you can.
You can do it in Borland C/C++ 3.1.
When I use FreeBSD/GNU 2.7.2 it knows it's a constant and won't let you do it.

The way to do it in Borland is to take the address of the constant, cast it as a pointer to the constant (which it is) and dereference it.

const int permanent = 41;
*(int *)&permanent = 29;
printf("%d\n", permanent);



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: any way to chane the val of const ??

how to find the sum of a 4 digit number www.computing.net/answers/programming/how-to-find-the-sum-of-a-4-digit-number-/1143.html

How to Grab the first file in dir www.computing.net/answers/programming/how-to-grab-the-first-file-in-dir/18259.html

i wanted to delete the content of a text file www.computing.net/answers/programming/i-wanted-to-delete-the-content-of-a-text-file/19673.html