4

Is there any lowercase null in any version of C++ language specification?

Background:

I was asked in an interview "Which of the following pointer initializations are valid?", and I filled the form something like:

// valid
    int* p1 = 0;
    int* p2 = 2-2;
    int* p6 = new int;
// invalid
    int* p3 = 1; 

    int z = 0;
    int* p4 = z;
// ???
    int* p5 = null;
Top-Master
  • 7,611
  • 5
  • 39
  • 71

3 Answers3

22

Is there any lowercase null in any version of the C++ language specification?

No.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
8

A one word answer would be NO.

try the below code

  #include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
    int *p = null;
    int *q = NULL;
    return 0;
}

This gives the below error on compilation:

error: ‘null’ was not declared in this scope

Which is self explanatory.

Christina Jacob
  • 665
  • 5
  • 17
2

The answer is written in some of the header files. NULL is the predefined macro in those header files such as **

-> #define NULL 0

**. Hence we can only define with uppercase "NULL" to avoid the compilation termination.

However, if you wish for lower case null, you can do so by defining the new macro or make charges in predefined macro in the header file. but be careful before you want to make these changes.

dragon
  • 132
  • 6