hello, i'm new to programming and i've been learning Jumping int C++. i've problem understanding why a pointer is used as a function name.
Secondly i do not get how the conditon if(size== next_element +1)
is met since next_element is initialised to zero and i dont know how it is incremented to meet this condition.
finally i'll be very greatful if the whole code is commented out for me(i know it is not encouraged) since i have been stuck trying to grasp this code for about a month now.other advices are welcomed
#include <iostream>
usingnamespace std;
int *growArray (int* p_values, int cur_size);
int main ()
{
int next_element = 0;
int size = 10;
int *p_values = newint[ size ];
int val;
cout << "Please enter a number: ";
cin >> val;
while ( val > 0 )
{
if ( size == next_element + 1 )
{
// now all we need to do is implement growArray
p_values = growArray( p_values, size );
}
p_values[ next_element ] = val;
cout << "Please enter a number (or 0 to exit): ";
cin >> val;
}
}
int *growArray (int* p_values, int cur_size)
{
int *p_new_values = newint[ cur_size * 2 ];
for ( int i = 0; i < cur_size; ++i )
{
p_new_values[ i ] = p_values[ i ];
}
delete p_values;
return p_new_values;
}
thnks for making my first problem clear to me.
for the second part , i mean to say how does
"next_element"
in
p_values[ next_element ] = val;
get increment that it meets the condition
if ( size == next_element + 1 )