Difference between nullptr and NULL, and between nullptrNULL
Note: The content in this article is excerpted from the network and the accuracy needs to be verified. At this stage, it is only for your reference. Respect the work of the author, the original link: http://www.2cto.com/kf/201302/190008.html
1. Why is there nullptr? When we assign an initial value to a pointer, we generally Write FILE * fp = NULL. Here is a NULL definition, which is generally defined as follows:
[cpp] #ifdef __cplusplus #define NULL 0 #else #define NULL ((void *)0) #endif
In the C language environment, NULL is defined as a void * pointer without function overloading. But in the c ++ environment, the situation becomes complicated. First, we cannot write such code FILE * fp = (void *) 0; it is illegal to assign void * directly to a pointer. The Compiler reports an error. We can only write code like this
[cpp] FILE* fp = (FILE*)0; // or FILE* fp = 0;
Therefore, in c ++, NULL is directly defined as an integer 0. In most cases, this does not cause any problems, but in case of heavy loads or template derivation, the compiler will not be able to give the correct results. For example:
[Cpp] void call_back_process (CCObject * target, void * data); bind (call_back_process, target, NULL); // The error function type is void *, however, we bind an integer 0.
2. nullptr Application Scenario: if our compiler supports nullptr, we should directly use nullptr to replace NULL macro definitions. They are completely equivalent during normal use. 3. Simulate nullptr implementation: Some compilers do not support nullptr, A New Keyword of c ++ 11. We can also simulate the implementation of a nullptr.
[cpp] www.2cto.comconst class nullptr_t_t { public: template<class T> operator T*() const {return 0;} template<class C, class T> operator T C::*() const { return 0; } private: void operator& () const; } nullptr_t = {}; #undef NULL #define NULL nullptr_t
What is the difference between NULL and null?
Top floor.
Before providing more details, it is only case-sensitive.
Where did you use C ++? It can only be null, without NULL. This NULL will be a macro definition. Mysql database? NULL is displayed and used, while null is a built-in NULL value. JS? VBS ?......
What is the difference between null and?
When data is unknown or unavailable, most database management systems store a special value called Null. Do not confuse it with zero (a valid value), zero-length string (a string data type that does not contain characters), or space characters. The SQL-3 standard defines a Null:
"... A special value used to indicate that any data value does not exist ..."
SQLServer has a null value to call the function:
ISNULL function: replace NULL with the specified replacement value.
Syntax
ISNULL (check_expression, replacement_value)
Parameters
Check_expression
Whether the expression is NULL is checked. Check_expression can be of any type.
Replacement_value
The expression returned when check_expression is NULL. Replacement_value must be of the same type as check_expresssion.
Return type
Returns the same type as check_expression.
Note
If check_expression is not NULL, the value of this expression is returned; otherwise, the value of replacement_value is returned.
Example:
Use ISNULL
The following example shows how to select the title, type, and price for all books in the titles table. If the price for a title is NULL, the price displayed in the result set is 0.00.
Select substring (title, 1, 15) AS Title, type AS Type,
ISNULL (price, 0.00) AS Price
FROM titles