Hello, Welcome back. This is quite interesting topic. Do I pass nil argument? The answer is yes. But How?
Nil Arguments?
Nil Arguments?
Here is my code </>If you want to check either your data structure it is empty or full. The above example show a demonstration, how the nil arguments pass or receive by methods. I want to create my own list for this example.
package mainimport ( "fmt") type List struct{ data int tail *List } var list List func(r *List)Insert()( *List) { if r == nil{ panic ("Empty List") } return r }func main() { var l *List = &list l.data = 3 l.tail = nil p := l.Insert() fmt.Printf("%p", p) fmt.Println(p.data) h := &list h.data = 1 h.tail = p c := h.Insert() fmt.Println(c.data, c.tail)}
If , you want to curious then you can Run this code. Thankyou, Have a great day.
Comments
Post a Comment