L
L
Ler Den2019-01-27 12:24:58
C++ / C#
Ler Den, 2019-01-27 12:24:58

Why does an error pop up when declaring an array?

#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
  int count;
  cout << "Enter the amount of numbers \n";
  cin >> count;
  int arrayNumber[count]; // ошибка здесь
}

Error - expression is not defined by a constant. At the same time, the code is launched in the cpp.sh
compiler . Why such a discrepancy in the results?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2019-01-27
@givemoneybiatch

HZ what kind of compiler cpp.sh is there, but you cannot create an array on the stack of an indefinite size at the compilation stage.
Use new and allocate as much as you need on the heap.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question