![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Apr 2008
Posts: 1
OS: xp
|
Constant array size
I know in C, arrays have to of a constant size.
However when I do something like: const int size = 10; int list[size]; I get thrown an error that the array size must be a constant expression (at the line where the array is declared). However, when in C++ when I do this it compiles fine. I'm using Visual Studio 2005, by the way. However, when I switch to "Compile as C++ code" it compiles the .c file correctly. So is this valid for any C code, or just the Visual Studio compiler? Last edited by alman9898 : 04-23-2008 at 02:47 PM. |
|
|
|
|
|
#2 (permalink) |
|
Registered User
Join Date: Jan 2008
Location: Harpers Ferry, WV
Posts: 241
OS: OS X 10.4.x
|
Re: Constant array size
Alman, welcome!! I haven't looked specifically at the differences between C and C++, but, if I remember, that is correct that in C++ it detects that size is an INT and it compiles okay. There are ways of creating dynamic arrays if you need that using malloc and such.
|
|
|
|
![]() |
| Thread Tools | |
|
|