In following codes, both the places 'p' is a global variable. In 1st case it's an array and 2nd case it's a pointer to an array. Do we get any performance benefit, while accessing 'p[ i ]' in the fixed size case ?
Fixed size array:
============
int p[1000];
void main ( )
{
for(int i = 0; i < 1000; i++)
p[ i ] = i;
}
Dynamic array:
===========
int *p = new int[1000];
void main ( )
{
for(int i = 0; i < 1000; i++)
p[ i ] = i;
}
Fixed size array:
============
int p[1000];
void main ( )
{
for(int i = 0; i < 1000; i++)
p[ i ] = i;
}
Dynamic array:
===========
int *p = new int[1000];
void main ( )
{
for(int i = 0; i < 1000; i++)
p[ i ] = i;
}
Comment