Q.1 problem

Q.1.why cant i use new int without pointers
for example

1
2
3
4
5
 int numItems;
cout << "how many items?";
cin >> numItems;
int *arr = new int[numItems];//correct
int arr=new int[numItems];//wrong 
Because that is how new is defined? I'm not sure what you are trying to ask.
closed account (Dy7SLyTq)
because a pointer points to a set of memory of type what ever type you used. ie
int + char + bool is meant to hold a value of something like a byte. not super important to the example however. a pointer points to a group of memory that you can write to, so doing memory like that allows you to control how much and is useful for things like when you need to create a buffer or a container
Topic archived. No new replies allowed.