user declaring the size of array?

is it possible to use this code ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main(int argc, const char * argv[]) {
	int number = 0;
	std::cout << "napis cifro za array\n";
	std::cin >> number;

	int array[number];

	
	std::cout << "array doug " << sizeof(array) / sizeof(int) << "\n";

	return 0;
}


It does work on xcode but doesn't in microsoft visual studio 2013. Where is the problem?
The size of the array has to be a compile time constant.
you need to dynamically allocate it. And why does function main have parameters?
MarkyMark wrote:
why does function main have parameters?

It's one of two forms of main that is guaranteed to work on every C++ compiler. It allows you to read command line arguments that was passed to the program.
Topic archived. No new replies allowed.