Hello guys this is again gh0st posting his lamest programs
but I know that they are useful for people which are starting with C++ so Ive decided to post them and to recive constructive critics too so feel free to say something:
ok the topic is pointers and the exercise is:
Suppose treacle is an array of 10 floats. Declare a pointer that points to the first element
of treacle and use the pointer to display the first and last elements of the array.
so the answer would be like this:
#include <iostream>
using namespace std;
int main()
{
double treacle[10]={0,1,2,3,4,5,6,7,8,9};
double * pointer = &treacle[0];// line 4
cout << *pointer;
cout << endl;
pointer = pointer + 9;// line 8
cout << *pointer;// line 9
cout << endl;
system("pause");
return 0;
}
resume: I make the use of a pointer and I declare it on line 4 then look at line 8 there is where I add +9 to pick the last element of the array that is going to be on the output of line 9.
I hope this was useful I will be posting more problems and more dificults problems about pointers .
more about pointers:
http://en.wikipedia.org/wiki/Pointer_%28computing%29