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 7513821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:18:14+00:00 2026-05-30T00:18:14+00:00

I learnt c++ about 6 years ago and I remember in the section about

  • 0

I learnt c++ about 6 years ago and I remember in the section about arrays unless you instantiated them using new then their size was static and could only be set in the source code with literal constants, not at run time.

But I was just playing around with a tutorial at

http://www.cplusplus.com/doc/tutorial/dynamic/

and tried to do it without new, and to my surprise it worked. Am I misunderstanding something?
The original code is at the mentioned URL but it isn’t too hard to see what it was from my modified code below.

I realise with strings, vectors etc… arrays aren’t really needed (probably explains why this issue never occurred to me) but just humour me 🙂

// rememb-o-matic
#include <iostream>
#include <new>
using namespace std;

int main ()
{
    int i,n;
//    int * p;
    cout << "How many numbers would you like to type? ";
    cin >> i;
    int p[i];
//    p= new (nothrow) int[i];
//    if (p == 0)
//        cout << "Error: memory could not be allocated";
    if (false)
        cout << "whut?" << endl;
    else
    {
        for (n=0; n<i; n++)
        {
            cout << "Enter number: ";
            cin >> p[n];
        }
        cout << "You have entered: ";
        for (n=0; n<i; n++)
            cout << p[n] << ", ";
//        delete[] p;
    }
    return 0;
}
  • 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-05-30T00:18:16+00:00Added an answer on May 30, 2026 at 12:18 am

    The code works because most compilers support Variable Length Arrays(VLA) through compiler extensions.

    However, Variable Length arrays are not allowed by the C++ standard, Using such a compiler extension would result in your code being non portable and non standard conformant.

    Since you are using gcc, Compile your code with -pedantic option and it will tell you it is not standard approved.

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

Sidebar

Related Questions

I am a C# programmer who started using ubuntu about 2 years ago. I'm
I've recently started to rewrite a project I did a few years ago using
I've got about three years c# experience. I'd like to learn some WPF and
I have learnt Python for about a month as a one year's PHPer.And I
I learnt a lot about weak_ptr working with share_ptr to break cyclic reference. How
In cleaning up this answer I learnt a bit about TRIGGER s and stored
One question about protected constructor. I learnt that the protected constructor can be used
I'm starting to learn about using Memcached with PHP and I was wondering; is
Hi I've been making iOS apps for about 3 1/2 years, I'm self taught
For years I've been reading about XML and I have just not quite grokked

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.