Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
int *arr=new int[size];

I am not getting what this thing is implying.

What I have tried:

What will be the difference if i change the value from 0 to 10? What i mean is this do
size will affect this? And what it all means ?
Posted
Updated 15-Sep-18 2:22am

1 solution

Quote:
What will be the difference if i change the value from 0 to 10?

What value? There is no "0"!

Look at the line of code, and break it down:
int *arr=new int[size];

int                        Integers are involved.
int *                      It's a pointer to an intger
int *arr                   The is called "arr" and it holds a pointer to an integer
int *arr=new               We want a new lump of memory allocated at run time.
int *arr=new int           The new memory will be integer(s)
int *arr=new int[...]      The new memory is an array of integers
int *arr=new int[size]

Allocate at run time an array of integers - the contents of size says how many integers the array will hold, and store a pointer to the first element in arr
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900