User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,050 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,333 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 2789 | Replies: 2
Reply
Join Date: Oct 2004
Posts: 3
Reputation: Flawless is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Flawless Flawless is offline Offline
Newbie Poster

Array declaration problem

  #1  
Nov 3rd, 2004
How can i declare an array with variable size? i dont want it to be dynamic array, it have to be static. I mean the following:

int size;
cin>>size;
float array[size];
the previous code when compiled gives me that a constant expression required for the array declaration, although an integer value is already assigned to "size" by "cin" ...
So is there a solution so i can modify the previous code so it'll work?? (without using a dynamic array)..
Appreciated..
Last edited by alc6379 : Nov 3rd, 2004 at 9:34 am. Reason: added [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Posts: 9
Reputation: gallas is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gallas gallas is offline Offline
Newbie Poster

Re: Array declaration problem

  #2  
Nov 3rd, 2004
The size of the array has to be known when compiling. That's why it must be a constant. The only way around this (that I know of) is allocating the array dynamically.
Reply With Quote  
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Array declaration problem

  #3  
Nov 4th, 2004
Why does it HAVE to be static? Is this an assignment where you need to puzzle out some way of doing this? gallas is right, memory allocation is for just such situations.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC