EvilZone
Programming and Scripting => C - C++ => Topic started by: gh0st on April 09, 2011, 06:38:09 PM
-
Hello guys this is again gh0st posting his lamest programs ;D 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 (http://en.wikipedia.org/wiki/Pointer_%28computing%29)
-
Just something you should be aware of, a pointer to a temporary variable is usually a bad idea... In this case it doesn't matter but if you return a pointer to a temporary variable from a function, you will usually get bad accesses etc.
-
uh I see dude Ive a question when you work in a project for example in a bot of a game like Warcraft 3 TFT you have to pick the adress from that game which located in the memory of the machine right? I just dont find another way which you can use to create that bot or aplication.
-
Take a look at BWAPI and how they do it for starcraft 1 bots. http://code.google.com/p/bwapi/ (http://code.google.com/p/bwapi/)
-
@bluechill: haha thanx for the link bro I was thinking something funny about bots matches on EZ doesnt matter if the game is horrible but It would be cool to see how bots fight :P
40,585 lines :O