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 213.67.240.59 (talk) at 14:16, 17 October 2017 (Inaccurate introduction). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
WikiProject iconComputing C‑class High‑importance
WikiProject iconThis article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
CThis article has been rated as C-class on Wikipedia's content assessment scale.
HighThis article has been rated as High-importance on the project's importance scale.

Inaccurate definition

can a constant be a kind of variable ? maybe it is a data type. —Preceding unsigned comment added by 82.137.200.8 (talk) 17:40, 19 November 2010 (UTC)[reply]

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. 213.67.240.59 (talk) 14:14, 17 October 2017 (UTC)[reply]

The code posted here has undefined behaviour. 213.67.240.59 (talk) 14:16, 17 October 2017 (UTC)[reply]