+ Reply to Thread
Results 1 to 3 of 3

Thread: What is 'nuptr' in C++0x?

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    48

    What is 'nuptr' in C++0x?

    What is 'nuptr' in C++0x?

    I just came across 'nullptr' keyword.

    How to use it?

    How it is different than NULL?

  2. #2
    There are different ways to assign NULL to a pointer.

    But this can create issue as described in below example. It also describes how to resolve such issues.

    Code:
    void ExecuteMe(int *pInteger)
    {
    	if (0 == pInteger)
    	{
    		printf("pInteger is NULL") ;
    	}
    }
    
    void ExecuteMe(int nInteger)
    {
    	printf("Value of nInteger is %s", nInteger) ;
    }
    
    void UseNullptr()
    {
    	//different type of (mis-leading) ways to declared pointer as null!
    	int*	pInt	= NULL ;
    	char*	pChar	= 0 ;
    	long*	plong	= '\0' ;
    
    	if (0 == pInt)
    	{
    		printf("pInt is NULL") ;
    	}
    
    	if (0 == pChar)
    	{
    		printf("pChar is NULL") ;
    	}
    
    	if (0 == plong)
    	{
    		printf("plong is NULL") ;
    	}
    
    	ExecuteMe(NULL) ; //which ExecuteMe method will get called? It is ExecuteMe(int nInteger)!
    
    	ExecuteMe(nullptr) ; //Now you get it right. This time it is ExecuteMe(int *pInteger)!
    }

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    48
    Nice example. I like your style.


+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts