user declaring the size of array?
Dec 1, 2014 at 7:02pm UTC
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?
Dec 1, 2014 at 7:36pm UTC
The size of the array has to be a compile time constant.
Dec 2, 2014 at 10:07am UTC
you need to dynamically allocate it. And why does function main have parameters?
Dec 2, 2014 at 10:14am UTC
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.