-4

node *head=NULL;

I don' undertand what does above code does? Could you help me ? Thanks,

  • 9
    Please read a good C++ book and follow some tutorials, this is very basic. Stack Overflow isn't a substitute for learning the languages you're using. – Mat Dec 03 '18 at 09:41
  • 2
    In order to understant this, you need first to understand the concept of pointer. Search in internet. There are a lot of good tutorials – Amadeus Dec 03 '18 at 09:42
  • There is a list of good books [here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – molbdnilo Dec 03 '18 at 09:43

2 Answers2

2

This here

node *head

Defines a pointer to a node, and calls that pointer head.

=NULL;

Here, NULL is assigned to it. According to this, NULL is:

The macro NULL is an implementation-defined null pointer constant, which may be

an integral constant expression rvalue of integer type that evaluates to zero (until C++11)

an integer literal with value zero, or a prvalue of type std::nullptr_t (since C++11)

In the end, the result is that head holds a value of 0. This way it can be queried, for instance using if (head == NULL){... or something similar.

When NULL is assigned to a pointer, this usually signifies that it's not pointing to a valid object (yet).

Blaze
  • 16,736
  • 2
  • 25
  • 44
-1

NULL is the macro defined for representing a pointer without a defined address. You can read more about in https://en.cppreference.com/w/cpp/types/NULL

aeroyorch
  • 56
  • 1
  • 6