Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:22:19+00:00 2026-06-11T16:22:19+00:00

Possible Duplicate: C/C++: Array size at run time w/o dynamic allocation is allowed? I’m

  • 0

Possible Duplicate:
C/C++: Array size at run time w/o dynamic allocation is allowed?

I’m in a class where we have a simple assignment to write a function that returns a pointer to a dynamic array and provide a stub to test it. I have this done so I’m not asking for help with the assignment. On the class blog another student suggests that it is intuitive that one should be able to do int Array[size]; where size is apparently a user defined variable.

I know that in standard C++, at least according to my text, an array must have a “constant integer expression…greater than zero” as a size declarator. Which implies to me that their example can’t work. In fact, with VS2010 you get three errors when you try.

However, they explain:

I know that, you know that, even the g++ compiler in my Ubuntu install
AND the Bloodshed compiler on my WinXP install know that. For certain
levels of “know that” one would expect “int Array[size];” to work
(like it has in both the prior classes).

But evidently it fails to run on some people’s VS compilers. One can
only assume that, since the common denominator is VS (and yes, I
confirmed this by asking a friend to check it on HIS box), that VS is
the problem. One of several.

There’s already confusion because the I know that... part is referring to me telling them that there shouldn’t be any reason to #include <new> in order to use new, but it seems they think we agree that there shouldn’t be any reason to use new to allocate a dynamic array.(?)

So the question is obvious. Are there any compilers which will accept int Array[size];, where size is not a const int without error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:22:20+00:00Added an answer on June 11, 2026 at 4:22 pm
    int Array[size];
    

    where size is not a constant expression is a variable length array. They’re a standard feature of C as of the 1999 ISO standard. The C++ standard has not adopted them, but some compilers support them as a language extension.

    (Any C++ compiler, when invoked in conforming mode, must at least issue a diagnostic for an array type with a non-constant size.)

    Incidentally, this isn’t directly related to the IDE you’re using; it’s controlled by the compiler that your IDE invokes.

    As for #include <new> there is a standard header by that name, but it’s not necessary for the new operator, which is built into the language. The <new> header provides several overloaded versions of operator new and a few other declarations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: C/C++: Array size at run time w/o dynamic allocation is allowed? In
Possible Duplicate: byte[] array pattern search I am trying to write a simple compression
Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains
Possible Duplicate: when do we need to pass the size of array as a
Possible Duplicate: String with array structure to Array I have an array as such
Possible Duplicate: Sizeof an array in the C programming language? I have an array
Possible Duplicate: Sizeof an array in the C programming language? I'm trying to write
Possible Duplicate: php sort array by sub-value I have a multidimensional array like the
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: Sizeof an array in the C programming language? Why is the size

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.