I want to write a program that gets an integer from an user eg. 5
The five should tell the program that 5 variables should be created. How would i approach this problem? must one use arrays? any input will be appreciated
Printable View
I want to write a program that gets an integer from an user eg. 5
The five should tell the program that 5 variables should be created. How would i approach this problem? must one use arrays? any input will be appreciated
Code:cin>>i;
int *pi;
pi = new int [i];
Thanks for the reply, but im a bit thick and rather new to c++. Can you give a quick explaination of whats going on??
This new expression allocates i objects of type int from the free store and returns the address of that object. We use that address to initialize the pointer pi.Code:int i;
cin>>i; //get input from user
int *pi;//define a pointer to int
pi = new int [i]; //new allocates memory. In this case,
//new allocates memory for i objects of type int.
//and pi points to the first elements of the allocated space.
http://faq.cprogramming.com/cgi-bin/...&id=1043284351
Does he know what pointers are yet?
I have a basic idea of pointers. Does it work the same as in c?
I wasnt to bad in c, but that was about 2 yrs ago.
I guess soQuote:
Originally Posted by Marlon