C4Swimmers Newsletter  

Article: C/C++ Pointers

Article: C/C++ Pointers

http://www.codeproject.com/KB/cpp/pointers.aspx
http://www.cs.cf.ac.uk/Dave/C/node10.html

  • Pointers are variables that point to an area in memory. You define a pointer by adding an asterisk (*) in front of the variable name (i.e. int *number).

  • You can get the address of any variable by adding an ampersand (&) in front of it, i.e. pNumber = &my_number.

  • The asterisk, unless in a declaration (such as int *number), should be read as “the memory location pointed to by.â€

  • The ampersand, unless in a declaration (such as int &number), should be read as “the address of.â€

  • You can allocate memory using the new keyword.

  • Pointers MUST be of the same type as the variables you want them to point to; so, int *number will not point to a MyClass.

  • You can pass pointers to functions.

  • You must delete memory that you have allocated by using the delete keyword.

  • You can get a pointer to an array that already exists by using &array[0];.

  • You must delete an array that is dynamically allocated using delete[], not just delete.

Courtesy:- http://structuredsand.wordpress.com/