Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

const confusion
I would like to make an array will will only be used for one purpose
and whose members are constant.
E.g. double arr[3] = { 0., 1., 2. };

I'd like arr to always point to this array and the entries to always
be these values. What is the right syntax for const in this situation?






Report this thread to moderator Post Follow-up to this message
Old Post
spasmous
04-03-08 03:07 AM


Re: const confusion
spasmous said:

> I would like to make an array will will only be used for one purpose
> and whose members are constant.
> E.g. double arr[3] = { 0., 1., 2. };
>
> I'd like arr to always point to this array and the entries to always
> be these values. What is the right syntax for const in this situation?

arr isn't a pointer, so it will never point to the array. It *is* the
array, insofar as it is the array's name. It is not a modifiable lvalue,
so you can't change it to be associated with some other array.

If by "always" you mean for the entire lifetime of the program, you can do
this by moving it to file scope, or by static-qualifying it, or both.

To make sure the values can't (legally) change, simply use const:

const double arr[3] = { 0., 1., 2. };

This defines and initialises an array of three const doubles. Strangely, so
would this:

double const arr[3] = { 0., 1., 2. };  /* same as before! */

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Report this thread to moderator Post Follow-up to this message
Old Post
Richard Heathfield
04-03-08 03:07 AM



Thousands of MP3s are waiting for you at http://mp3files4free.com/

Our new hits:
"Model 500 - Starlight (M 69 Original Mix)" free mp3 downloa
d
"Drum & Bass - Various
 Artists - Changes (Calibre remix) (Danny Byrd feat. Somniare)" free mp3 download[
/URL]
[URL=http://www.mp3files4free.com/mp3download.php?aid=218571&song=Grant_Green-What
_Is_This_Thing_Called_Love]"Grant Green - What Is This Thing Called Love" free mp3
 download
"Cerrone - Living On Love" free mp3 download
"Toni Braxton - Let It Flow" free mp3 download
"Die Arzte - Circuit Breaker Mix" free mp3 download
"Billy Joel - Movin' Out (Anthony's Song)" free mp3 download[/U
RL]
[URL=http://www.mp3files4free.com/mp3download.php?aid=218571&song=Tommy_Guerrero-A
 s_the_Sea_Holds_Creatures_Vast_and_True]
"Tommy Guerrero - As the Sea Holds Creatur
es Vast and True" free mp3 download
"House - Various Artists - Self
ish (Self Service feat Vladimir Luxuria)" free mp3 download
"Electronic - Various Artists - Magic (Apollo)" free mp3
 download
"Neal Morse - Interlude" free mp3 download
"Kanye West - Graduation Day" free mp3 download
"Louis Armstrong - On Treasure Island" free mp3 download
"Hammerfall - Imperial" free mp3 download
"Pop - Various Artists - Strawberry
 Fields Forever - Sandy Farina" free mp3 download
"Soundtrack - Various Artist
s - Just Like Honey (The Jesus and Mary Chain)" free mp3 download
"Lindsey Buckingham - Flying Down Juniper" free mp3 downloa
d
"Meat Loaf - Life Is a Lemon and I 
Want My Money Back - Meat Loaf" free mp3 download
"Brian Eno, Jon Hassell - Ba-Benzele" free mp3 download
"Pop - Various Artists - Peter Brix
 (Brixx) - Video video - Denmark" free mp3 download
"Isao Tomita - Jesu, Joy Of Man's Desiring" free mp3 downloa
d
"Lupe Fiasco - Life" free mp3 download
"Asymetrix - Predator" free mp3 download
"
Doro - Hellbound" free mp3 download

Report this thread to moderator Post Follow-up to this message
Old Post
Enshlolee62
04-05-08 07:51 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 12:52 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.