Jump to content

Talk:Constant (computer programming)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Andrew1~enwiki (talk | contribs) at 00:12, 30 July 2009 (Created page with '== Inaccurate introduction == "In computer programming, a constant is a special kind of variable whose value '''cannot''' be altered during program execution." This...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Inaccurate introduction

"In computer programming, a constant is a special kind of variable whose value cannot be altered during program execution." This isn't completely accurate as there are exceptions to the 'rule'. The following C++ code will change the value of a constant:

const int a = 1;
int *ptr_a = (int*)(&a);
cout << a; // outputs 1
*ptr_a = 2; // legal statement
cout << a; // outputs 2

It is also possible to change a #define defined symbolic constant much easier. Andrew (talk) 00:12, 30 July 2009 (UTC)[reply]