Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does struct have default constructor?

I read somewhere that using new to instantiate a struct assigns default values to all of the instance's variables. Does it imply that a struct will have its values initialized through a default hidden constructor?

like image 385
chakmeshma Avatar asked Aug 27 '26 23:08

chakmeshma


1 Answers

Does it imply that a struct will have its values initialized through a default hidden constructor?

Yes, in the sense that all member fields will be set to their default(T) values.

In practice, the compiler could just do something like memset(ptr, 0, sizeInBytes) . What actually happens is an implementation detail.

like image 144
Henk Holterman Avatar answered Aug 30 '26 14:08

Henk Holterman