answersLogoWhite

0

What is Nil value?

Updated: 11/1/2022
User Avatar

Wiki User

6y ago

Best Answer

Several programming languages use a pointer value of Nil to indicate that the pointer does not point to anything.

While the internal coding for Nil is usually not relevant to the programmer, it is typically the number 0 (but any value that would not be a valid memory address for storing such data structures at could be used).

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is Nil value?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Null in programming?

in Russian Null means zero. in some languages Null is a macro for zero. in others Null is a single-tone object which referes to the value Null and thus could be compared to other values. Null has many names from nill Nill nil in diffrent languages. most of the time, Null is used to indicate, no value is set to a variable.


Write the algorithm for in order traversal?

Inorder(p) { If p = nil return; Inorder(p.left) process(p.data) Inorder(p.right) }


Is tube light run without choke?

No it will not. If you need increase the supply voltage and remove the choke.


What is the difference between pre and post processing incrementation?

To increment a value by 1, you have 4 choices:value++;++value;value += 1;value = value + 1;Pre and post processing incrementation/decrementation refers to the first two: ++value and value++.Both do exactly the same, as both will increase the value of 'value' by one.If we have a situation like this:int value = 0;int value1 = 0;value1 = value++;This essentially means:value1 = value;value = value + 1;Where ++value means:value = value + 1;value1 = value;


How can I initialize a type that is a pointer to a struct in Go?

For the purpose of clarification, you cannot initialise types, you can only initialise variables (or constants) of a type. A variable (or constant) is known as an "instance" or "object" of the type. All instances of a type must be named. A pointer variable allows us to "refer" to a named object of the pointer's type. this is achieved by storing the memory address (the starting address) of that object. By changing the address stored in the pointer variable, the same pointer variable can be used to refer to different objects in memory. This is useful when passing objects to functions because if we pass objects directly (by name), the function receives a copy of the object. This is known as "pass by value". However, when a function expects a pointer variable rather than a named variable, the address of the object is copied instead. This is known as "pass by reference" and allows the function to operate (indirectly) upon the object being referenced rather than a copy of the object (any changes to a copy are not reflected in the original object). Passing by reference is particularly useful when the object is large and complex. To improve efficiency, we must avoid making any unnecessary copies of large or complex objects. Functions that do not modify an object are a prime example; there is no point in copying an object that will not be modified. If we wish a function to modify the object, we must pass the object by reference. The only time we should copy an object is when we're not interested in the modifications made by a function, or when we want to compare the changes that were made. In these cases we simply make a copy of the object before passing that copy to the function by reference. When working with concurrency, however, it is best to use pass by value semantics. In this way, each thread works with a local copy of your object, and thus avoids "race conditions", where one task is accessing an object that is being modified by another task, which can lead to unpredictable results. Pointer variables are said to "point at" the memory the refer to (hence they are called pointers). To access the value being pointed at, the pointer variable must be dereferenced. However, in the case of pointer to struct variables, the dereferencing is transparent. All variables in Go are implicitly initialised with the default "zero" value for its type. The zero value of a pointer variable is always "nil" (regardless of which type of pointer). You must never dereference a pointer variable that holds the nil value so always check the pointer is non-nil. Equally, you must never dereference a pointer to an object that no longer exists in memory. Always nil your pointers as soon as you are finished with them. The following example demonstrates how to initialise a pointer variable to a struct: package main import "fmt" type Point struct { X int Y int } func main () { v := Point{1, 2} // instantiate an object of type Point p := &v // assign the address of v to pointer p (p's type is inferred from v) fmt.Println(*p) // print the indirect value of v (dereference p) }