PDA

View Full Version : hello world with pointers



stupid_mutt
10-01-2001, 12:54 PM
I would try this but Im at school. I dont know if this works but it sure is cool if it does.

int main()
{
char *TextPtr;

TextPtr=0xB800;

*TextPtr+0='h'; // h
*TextPtr+1=7;
*TextPtr+2='e'; // e
*TextPtr+3=7;
*TextPtr+4='l'; // l
*TextPtr+5=7;
*TextPtr+6='l'; // l
*TextPtr+7=7;
*TextPtr+8='o'; // o
return 0;
}

Just thought I would share that thought.

SilentStrike
10-01-2001, 02:26 PM
*TextPtr+5

Look at all these. The value pointed by TextPtr (char) plus 5, and then assign it something. Esentially, you are assigning to a temporary integer. It would need to be like this. *(TextPtr + 5). And even then, you would need to allocate the memory either on the stack.. ie

char* TextPtr = new char[11];

or on the stack

char TextPtr[11];

Nick
10-01-2001, 03:08 PM
It should work I think provided your in the right video
mode and that your compiler supports that way of setting a pointer to a integer, some don't. I'll try it and see what happens.

Nick
10-01-2001, 03:10 PM
dereferancing as greater precidence than addition though.