Wednesday, June 19, 2019

Do I, receiver, nil argument?

Hello,  Welcome back. This is quite interesting topic. Do I pass nil argument? The answer is yes. But How?

Nil Arguments?
         Here is my code </>     
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 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.  
   If , you want to curious then you can Run this code. Thankyou, Have a great day.

No comments:

Post a Comment

Do you support us?

Business address
0x1D24D8f27ea73ff604C7685246bdC6ae55bddaEF

خیال قیام پزر

 اکثر دل میرا ڈھڑتا ہے، جب کبھی  بادل ٹھہر جاتے ہیں، میرے آنگن کے  چاروں ظرف اک چاند ہے اُس کا، خیال قیام پزر ہوتا دل میں میرے ، کوئی گ...

Achieves