0

I know this question has been asked many times before. But everything I went through indicated it is not possible to declare a variable size array at run time unless we use pointers or vectors. But I am always able to take the array size input in a variable(say n) from user and then declare a array of size n. It never gives any warning or error in codeblocks ,vs code or for that matter any coding website.

   int n;
   cin>>n;

   int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];

    }  

My this code always works, but i don't understand How!!!! Here is my Build message

Thanks in Advance

4
  • 3
    It works because the compiler you are using supports VLAs as an extension. VLAs are not part of the portable C++. Commented May 21, 2020 at 12:19
  • 1
    @Ron - IMHO, you should expand your comment in an answer Commented May 21, 2020 at 12:20
  • 1
    t never gives any warning or error in codeblocks ,vs code or for that matter any coding website. -- Try Visual Studio using Visual C++, and you will see the error. See this Commented May 21, 2020 at 12:20
  • 1
    @max66 Appreciate it. There seems to be a duplicate already. Commented May 21, 2020 at 12:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.