make an empty slice

51 views
Skip to first unread message

sasikala tholisam

unread,
Jun 6, 2019, 9:49:00 AM6/6/19
to golang-nuts

test []Exam

type Exam struct{

Time uint32

LogType uint32

Data [32]byte

}

test is a slice of []Exam..It should be an empty slice...how to make test as empty?

Mark Bauermeister

unread,
Jun 6, 2019, 9:56:03 AM6/6/19
to golang-nuts
You mean a slice that is not of type Exam?

test []int

Should work.
Your slice does need to adhere to some type.

Marvin Renich

unread,
Jun 6, 2019, 10:56:06 AM6/6/19
to golang-nuts
* sasikala tholisam <gr.sasi...@gmail.com> [190606 09:49]:
After changing the first line to

var test []Exam

your code will produce an empty slice for test. You can check its
length with len(test) and it will be 0. Here's the code on the
playground: https://play.golang.org/p/UtZ-YhNXojk

...Marvin

Reply all
Reply to author
Forward
0 new messages