
Pointers of every type have a special value known as null pointer value of that type. Because of the function-to-pointer implicit conversion, the address-of operator is optional: In all cases, it is the caller's responsibility to cast the pointer to the correct type before use.Ī pointer to function can be initialized with an address of a non-member function or a static member function. pthread_create expects a user-provided callback that accepts and returns void *. Pointers to void are used to pass objects of unknown type, which is common in C interfaces: std::malloc returns void *, std::qsort expects a user-provided callback that accepts two const void * arguments. Pointers to void have the same size, representation and alignment as pointers to char. If the original pointer is pointing to a base class subobject within an object of some polymorphic type, dynamic_cast may be used to obtain a void* that is pointing at the complete object of the most derived type. Int n = 1 int * p1 = &n void * pv = p1 int * p2 = static_cast (pv ) std:: cout << *p2 << ' \n' // prints 1 The reverse conversion, which requires static_cast or explicit cast, yields the original pointer value: Pointer to object of any type can be implicitly converted to pointer to void (optionally cv-qualified) the pointer value is unchanged. This makes it possible to use all pointers of random origin as keys in standard associative containers such as std::set or std::map. where not all bits of the pointer are part of a memory address and have to be ignored for comparison, or an additional calculation is required or otherwise pointer and integer is not a 1 to 1 relationship), provide a specialization of std::less for pointers that has that guarantee. if they are implemented as addresses within continuous virtual address space. Many implementations also provide strict total ordering of pointers of random origin, e.g. If Derived is polymorphic, such pointer may be used to make virtual function calls.Ĭertain addition, subtraction, increment, and decrement operators are defined for pointers to elements of arrays: such pointers satisfy the LegacyRandomAccessIterator requirements and allow the C++ library algorithms to work with raw arrays.Ĭomparison operators are defined for pointers to objects in some situations: two pointers that represent the same address compare equal, two null pointer values compare equal, pointers to elements of the same array compare the same as the array indexes of those elements, and pointers to non-static data members with the same member access compare in order of declaration of those members. Note that two pointers that represent the same address may nonetheless have different values. A pointer past the end of an object represents the address of the first byte in memory after the end of the storage occupied by the object. the null pointer value for that type, orĪ pointer that points to an object represents the address of the first byte in memory occupied by the object.a pointer past the end of an object, or.a pointer to an object or function (in which case the pointer is said to point to the object or function), or.Typically, mentions of "pointers" without elaboration do not include pointers to (non-static) members.Įvery value of pointer type is one of the following: There are no pointers to references and there are no pointers to bit fields. It can be another pointer declarator (pointer to pointers are allowed) (since C++11) optional list of attributesĬonst/volatile qualification which apply to the pointer that is being declared (not to the pointed-to type, whose qualifications are part of decl-specifier-seq)Īny declarator other than a reference declarator (there are no pointers to references). nested-name-specifierĪ sequence of names and scope resolution operators :: 2) Pointer to member declarator: the declaration S C :: * D declares D as a pointer to non-static member of C of type determined by decl-specifier-seq S.
