Whats in this post?
- Background and Explanation of the code
To copy code: Click “View Source” on the right of this code snippet.
Background and Explanation of the code
p = new int [n] ;
on execution allocates memory for storing n integer values at run time and returns the address of the first element which is stored in pointer p. The dynamically allocated memory can be referred using pointer variable p.So *(p+i) refers to the ith element.The user first enter the array elements and then calculates the average of numbers.
Enter how many elements = 4
Enter value : 1 =20
Enter value : 2=25
Enter value : 3 =15
Enter value : 4 = 35
Average of given value = 23.75