• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++: Need to create an array with a size declared by the user.

Usul

Golden Member
as topic, I need to find a way to declare an array after I ask the user for a size.
I personally think it's impossible, since the numbere of variables in an array is stucked into the code, but as you see i'm not really into this stuff, and my Comp Sci teacher says it can be done, but "forgot"how, and offered me a huge extra credit, so.....

 
It's a piece of cake to do this, but you need to understand how pointers work.

int *array_ptr, size;

cout << &quot;Enter array size\n&quot;;
cin >> size;

array_ptr = new int [size];
 
Back
Top