When we create an array on the stack most compilers will want to know the size of the array which will be determined at compile time so generally we can't get a user to enter the size of the array from standard input,but what if we are calling a function and we pass that number entered from the user into a function to create an array?
isn't this function been called at compile time?
for example if the user enters 1 isn't this function being called at run time? Since the user will determine whether or not the function will be called.
or is this still compile time?
#include <iostream>
void someFunction(int number){
int sampleArray[number];
for(int i = 0; i < number; i++){
sampleArray[i] = 0;
}
// I know what I'm doing is pointless but is it possible?
}
int main()
{
int number = 0;
int choice = 0;
std::cout << "do you want to create an array? press 1 for yes" << std::endl;
std::cin >> choice;
if(choice == 1){
std::cout << "enter size" << std::endl;
std::cin >> number;
someFunction(number);
}
}