Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is lowercase null valid in C++?

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;
like image 318
Top-Master Avatar asked Nov 28 '22 05:11

Top-Master


2 Answers

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

No.

like image 189
Nikos C. Avatar answered Nov 29 '22 17:11

Nikos C.


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.

like image 29
Christina Jacob Avatar answered Nov 29 '22 17:11

Christina Jacob