
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pointer Template in C++
In this article we will be discussing the working, syntax and examples of std::is_pointer template in C++ STL.
is_ pointer is a template which comes under the <type_traits> header file. This template is used to check whether the given type T is a pointer type or not.
What is a Pointer?
Pointers are non-static types which hold an address of another type or in other words which points to some memory location in the memory pool. With help of an asterisk (*) we define a pointer and when we want to refer the specific memory which the pointer is holding then also we use asterisk(*).
They are the type which can be initialised as null and can later change the type, as per the need.
Syntax
template <class T> is_pod;
Parameters
The template can have only parameter of type T, and check whether the given type is a Pointer or not.
Return value
It returns a Boolean value, true if the given type is a pointer variable, and false if the given type is not a pointer.
Example
Input: is_pointer<int>::value; Output: False Input: is_pointer<int*>::value; Output: True
Example
#include <iostream> #include <type_traits> using namespace std; class TP{ }; int main() { cout << boolalpha; cout << "checking for is_pointer:"; cout << "\nTP: " << is_pointer<TP>::value; cout << "\nTP*: " << is_pointer<TP*>::value; cout << "\nTP&: " << is_pointer<TP&>::value; cout << "\nNull Pointer: "<< is_pointer<nullptr_t>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_pointer: TP: false TP*: true TP&: false Null Pointer: false
Example
#include <iostream> #include <type_traits> using namespace std; int main() { cout << boolalpha; cout << "checking for is_pointer:"; cout << "\nint: " << is_pointer<int>::value; cout << "\nint*: " << is_pointer<int*>::value; cout << "\nint **: " << is_pointer<int **>::value; cout << "\nint ***: "<< is_pointer<int ***>::value; return 0; }
Output
If we run the above code it will generate the following output −
checking for is_pointer: int: false int*: true Int **: true Int ***: true