Why use this segment
Code:
#include <iostream>
using namespace std;
int main ()
{
int numbers[5];
int * p;
p = numbers; *p = 10;
p++; *p = 20;
p = &numbers[2]; *p = 30;
p = numbers + 3; *p = 40;
p = numbers; *(p+4) = 50;
for (int n=0; n<5; n++)
cout << numbers[n] << ", ";
return 0;
}
instead of this segment?
Code:
#include <iostream>
using namespace std;
int main ()
{
int a[5];
int *b;
b = a; *b = 10;
b = a; *(b+1) = 20;
b = a; *(b+2) = 30;
b = a; *(b+3) = 40;
b = a; *(b+4) = 50;
for (int n=0; n<6; n++)
cout << a[n] << ", ";
return 0;
}
Does the first, seemingly more complicated block do something more than the second block? Even though both print the same thing?
NOTE in the first block, p is equivalent to b in the second block. and "numbers" is equivalent to a.