type_traits::is_null_pointer in C++

The type_traits::is_null_pointer of C++ STL is used to check whether the given type is null_pointer or not. It returns the boolean value either true or false. Below is the syntax for the same:

Header File:

#include<type_traits>

Syntax:

template class T struct is_null_pointer;

Parameter: The template type_traits::is_null_pointer accepts a single parameter T (Trait class) to check whether T is a null_pointer or not.

Return Values:



  • True: If the type is a null_pointer.
  • False: If the pointer is not null pointer.

Below programs illustrate the std::is_null_pointer template in C++ STL:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// is_null_pointer template
  
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
  
// Driver Code
int main()
{
  
    cout << boolalpha;
    cout << "is_null_pointer:" << endl;
    cout << "int *&: "
         << is_null_pointer<decltype(nullptr)>::value
         << '\n';
    cout << "int *[10]: "
         << is_null_pointer<int * [10]>::value
         << '\n';
    cout << "float *: "
         << is_null_pointer<float*>::value
         << '\n';
    cout << "int[10]:"
         << is_null_pointer<int[10]>::value
         << '\n';
  
    return 0;
}

chevron_right


Output:

is_null_pointer:
int *&: true
int *[10]: false
float *: false
int[10]:false

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate
// is_null_pointer template
  
#include <bits/stdc++.h>
  
#include <type_traits>
using namespace std;
  
// Driver Code
int main()
{
  
    cout << boolalpha
         << is_null_pointer<decltype(nullptr)>::value
         << endl
         << is_null_pointer<int*>::value
         << endl
         << is_pointer<decltype(nullptr)>::value
         << endl
         << is_pointer<int*>::value
         << endl;
}

chevron_right


Output:

true
false
false
true

Reference: http://www.cplusplus.com/reference/type_traits/is_null_pointer/

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.