Pointers are objects that point (in memory) to another object. Their usefulness lies in their ability to dynamically manage memory and data structures. They are also very dangerous because there is a tendency to not adhere to all the rules when dealing with pointers and dynamic memory.
1. Never use a pointer without initializing it with a proper allocation request.
2. Always check a memory allocation request for failure.
3. Never use a pointer beyond the bounds of the original allocation.
4. Never use a pointer after it has been deallocated.
5. Alway deallocate a prior memory allocation when you are done using it.
If xyz is the name of an object in memory, then &xyz is it's address. If pxyz is a pointer to an object of type xyz, then the statement pxyz = &xyz would initialize pxyz to point to xyz. At that point, you could refer to xyz using *pxyz.
If pabc is a pointer to an object of type abc, then the statement pabc = malloc(100*sizeof(abc)) would allocate an array of 100 objects of type abc from the heap, and initialize pabc to point to the first one. You could then use the array with pabc[n] syntax or with *(pabc+n) syntax. You would deallocate the array with free pabc.
C++ Specific:
If pqrs is a pointer to an object of class type qrs, then the statement pqrs = new qrs would allocate memory from the heap, initialize pqrs to point to the object, and fire the constructor for that class. You could then invoke methods of the class with pqrs->method(), etc. or you delete the class with delete pqrs, said deletion firing the destructor.
The pointer that points to a block of memory that does not exist is called a dazzling pointer or wild pointer
An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.
It is a type of pointer dereference operation. If you have a pointer p to an object that has methods or attributes, you can say (*p).m to refer to the m method of the object, or you can say p->m to do the exact same thing.
An asterisk in C++, such as int *data, is what's known as a pointer. A pointer is like a regular variable, but instead of holding a value, a pointer holds the memory location of the value. It's a somewhat difficult concept, and you can learn more about it here: See related links section below...
Yes, C++ has pointers, which are references to memory locations. which are variables that store memory addresses, or NULL (zero). If the pointer is non-NULL, the pointer is said to dereference the object (or variable) residing at the stored memory address, which permits indirect access to that object so long as the object remains in scope.
Multiplication is yet another thing, what you should never do with pointers.
The pointer that points to a block of memory that does not exist is called a dazzling pointer or wild pointer
Address of the current object.
a pointer that is not pointing to anything
An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.
The function ftell returns the position of the file pointer for a file.
Yes. All string variables are pointers as are other arrays.
It is a type of pointer dereference operation. If you have a pointer p to an object that has methods or attributes, you can say (*p).m to refer to the m method of the object, or you can say p->m to do the exact same thing.
An asterisk in C++, such as int *data, is what's known as a pointer. A pointer is like a regular variable, but instead of holding a value, a pointer holds the memory location of the value. It's a somewhat difficult concept, and you can learn more about it here: See related links section below...
Example: void foo( MyClass& object ){} // function with call by reference signature MyClass* p = new MyClass(); // instantiate a pointer to MyClass foo( *p ); // call by reference using the pointer
Yes. If the ports are memory mapped, then you simply need a pointer to that address, and you need to declare the pointer as volatile. If they are I/O mapped, then you need to create an _asm{} block.
The "this" pointer is a pointer to the instance of the object, with scope within a member function of that object. It is not always necessary to use it, as references to variables defined in the object will be implicitly prefixed with "this->", but it can resolve name scoping problems, and it can make the code more readable.