Pointers
suggest changeA pointer stores the address of an object or function, or a special null pointer value. Pointers let code refer to objects without copying them and can point to both built-in and user-defined types.
Pointers commonly use the dereference (*), address-of (&), and member-access (->) operators. * accesses the pointed-to object, -> accesses one of its members, and & obtains an object's address.
Syntax
- <Data type> *<Variable name>;
- <Data type> *<Variable name> = &<Variable name of same Data type>;
- <Data type> *<Variable name> = <address or null pointer>;
- int *foo; // A pointer to an integer
- int *bar = &myIntVar;
- long *bar[2];
- long *bar[] = {&myLongVar1, &myLongVar2}; // The initializer sets the bound: long *bar[2]
Be aware of problems when declaring multiple pointers on the same line.
int* a, b, c; //Only a is a pointer, the others are regular ints.
int* a, *b, *c; //These are three pointers!
int *foo[2]; // foo[0] and foo[1] are pointers. *foo[0] is an int.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents