Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > declaring const...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 10 Topic 43644 of 48022
Post > Topic >>

declaring constant array without initializing all the elements

by Pavan <pavan734@[EMAIL PROTECTED] > Mar 3, 2008 at 06:10 AM

Hi,
    I need to create a consant array of larze size but however its
elements can be calculated using an equation, say for example I need
an int arry of 20 elements where each element will be

arr[i] = 2 + (i*i)

But I want arry to be constant. How can I declare such a constant
array without actually defining all the elements?

I could think of one way:
Declare a non const arry

int arr_non_const[20];
for(int i=0; i <20; i++)
{
   arr_non_const[i] = 2 + (i*i);
}

Now declare a constant pointer

const int* arr = arr_non_const;

Is it correct? Is there any other way to do so.
 




 10 Posts in Topic:
declaring constant array without initializing all the elements
Pavan <pavan734@[EMAIL  2008-03-03 06:10:10 
Re: declaring constant array without initializing all the elemen
"Eric Pruneau"   2008-03-03 09:46:35 
Re: declaring constant array without initializing all the elemen
Abhishek Padmanabh <ab  2008-03-03 07:22:36 
Re: declaring constant array without initializing all the elemen
Lionel B <me@[EMAIL PR  2008-03-03 15:30:15 
Re: declaring constant array without initializing all the elemen
James Kanze <james.kan  2008-03-04 00:36:02 
Re: declaring constant array without initializing all the elemen
James Kanze <james.kan  2008-03-04 00:39:50 
Re: declaring constant array without initializing all the elemen
Lionel B <me@[EMAIL PR  2008-03-04 10:09:46 
Re: declaring constant array without initializing all the elemen
James Kanze <james.kan  2008-03-04 04:37:29 
Re: declaring constant array without initializing all the elemen
Lionel B <me@[EMAIL PR  2008-03-04 13:16:33 
Re: declaring constant array without initializing all the elemen
James Kanze <james.kan  2008-03-04 14:42:25 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 11:23:48 CDT 2008.