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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:37:40+00:00 2026-06-11T13:37:40+00:00

#include <iostream> using namespace std; int main(int argc, const char * argv[]) { int

  • 0
#include <iostream>

    using namespace std;

    int main(int argc, const char * argv[])
    {

        int size;
        cin >> size;
        int myArray[size]; //this shouldn't compile , right ? 

        return 0;
    }

I thought this wouldn’t compile, but it does actually (using the g++ command).

What I found out later is that GCC actually allows variable-size arrays even if by standard C++ doesn’t support variable-size arrays, Which is weird ! Because I hear everyone saying that the only way to create a variable-size array is to use dynamic allocation like int* array = new int[size]; or better std::vector. I thought GCC wouldn’t allow that piece of code !

Anyway, My theoretical question is, the myArray array is allocated in the heap or stack area ?

  • 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-11T13:37:41+00:00Added an answer on June 11, 2026 at 1:37 pm

    That is an extension on the compiler side. How does it work? Well, it works only to some extent.

    The implementation basically moves the stack pointer a quantity that is dependent on the size of the array, and calls the memory in the middle by the name of the array. It only works to some extent because in VLAs the size is not an integral part of the type, which means that many constructs that can be used on regular arrays cannot be done with this type, like for example passing the array to a template by reference… sizeof is usually supplied but implemented as a runtime construct.

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

Sidebar

Related Questions

#include <iostream> using namespace std; int main (int argc, char* const argv[]) { int
The following code #include <iostream> using namespace std; int main() { const char* const
#include <iostream> using namespace std; int main(void){ int size = -2; int* p =
#include <iostream> #include <iomanip> using namespace std; int main() { char array[10]; for(int i
#include <iostream> using namespace std; int main() { int a, b, c, max; cout<<a=;
#include <iostream> using namespace std; int main() { cout << !!!Hello World!!! << endl;
Example: #include <iostream> using namespace std; int main() { wchar_t en[] = LHello; wchar_t
Short problem: #include <iostream> using namespace std; int main() { double **T; long int
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile; myfile.open

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.