Advertisement

Pointer Notation

Started by August 03, 2000 09:09 PM
3 comments, last by CoolMiker 24 years, 5 months ago
Anyone willing to give me a little lesson on pointer notation?
"The Key To Creation Is Destruction"
OK, I give up: what do you mean by pointer notation?
Advertisement
Obviously he is referring to the notation of pointers.
Obviously.

pointer+offset; 


Thats the basics of pointer notation... . Its basically just a different way of accessing an element of an array. Say you have a pointer to an array of 5 bytes, and you want the 4th one, you''d do something like "*(memLoc+4)"
I think he was looking for something a little more helpful.

Pointer notation is one of the hardest topics to grasp as a newbie C/C++ programmer. Anyway here is a quick reference that should help you find your way through all the invalid pointers that crash your program.

bool foo {  int number;  int *pnumber;  char letter;  char* pletter;  char array[5] = "Hello";  struct my_struct {    int member;  };  struct mystruct *pstruct, anotherstruct;  //Standard assignment you should be familiar with.  number = 5;   pnumber = &number   if (*pnumber == 5) {    letter = ''e'';    pletter = &letter  }  //Note: I know the two conditions below are equivalent.  if ((*(array+1) == *pletter) || (array[1] == letter) {    anotherstruct.member = 5;    pstruct = &anotherstruct  }  if (pstruct->member == *pnumber) {    return (YOU_UNDERSTAND_POINTERS);  }} 


If you can understand how I got pstruct->member to equal the value at the memory location of pletter then you will pretty much have a decent grasp on pointers. Remember that classes behave exactly the same as structs do with respect to pointer notation. Arrays have nice properties that allow you to address things much more efficiently than in other languages.(though you can screw up more easily) Get yourself a book that teaches C and you might be able to find a good chapter on pointers and what they can be used for.

Hope this helps
Kressilac
Derek Licciardi (Kressilac)Elysian Productions Inc.

This topic is closed to new replies.

Advertisement